2016-05-23 26 views
1

這是我的HTML

<form class="login-form" method="POST"> 
     <input type="password" placeholder="password" id="password" name="password"/> 
     <input type="button" id="login" name="login" value="login" onclick="redirect()"></input> 
     </form> 

而我的JS

  <script type="text/javascript"> 
     $(document).ready(function redirect(){ 
     $("#login").click(function(){ 
     var pwd="<?php echo $pwd?>"; 
     alert("<?php echo "this is pass".$pword?>"); 
     if(userID===user && pwd===pass) 
     { 
     window.location.href = 'http://localhost/Annapoorna/Welcome_Page.php'; 
     } 
     else 
     { 
     alert("Please enter correct username and password!"); 
     } 
     } 
    }); 
}); 
</script> 

和PHP

<?php 
    $username=""; 
    $pwd=""; 
    $pword=""; 
    function confirm(){ 


     if(isset($_REQUEST['password'])) 
     { 
      $pword = $_REQUEST['password']; 
     } 

     $sth->execute(array(':pass'=>$pword)); 
     foreach ($sth->fetchAll() as $row) { 
     $username=$row['username']; 
     $pwd=$row['password']; 
     echo $pword; 
     } 
    ?>  

$ _ POST沒有返回任何值。已嘗試$ _REQUEST,但沒有工作。已將ID和名稱分配給密碼字段。

+2

'window.location.href ='http://localhost/Annapoorna/Welcome_Page.php';'參數在哪裏?提交表單或將參數添加到URL。不只是重定向 – Thamilan

+0

嘿,頁面打開。所以沒有錯。 –

+0

頁面將打開,參數在哪裏?你沒有通過那些 – Thamilan

回答

1

您沒有提交表單,只是將用戶重定向到該頁面。在JavaScript試試這個

<form id='myForm' class="login-form" method="POST" action='/Annapoorna/Welcome_Page.php'> 
    <input type="password" placeholder="password" id="password" name="password"/> 
    <input type="button" id="login" name="login" value="login" onclick="redirect()"></input> 
    </form> 

<script type="text/javascript"> 
    $(document).ready(function redirect(){ 
    $("#login").click(function(){ 
    var pwd="<?php echo $pwd?>"; 
    alert("<?php echo "this is pass".$pword?>"); 
    if(userID===user && pwd===pass) 
    { 
    $('#myForm').submit(); 
    } 
    else 
    { 
    alert("Please enter correct username and password!"); 
    } 
    } 
}); 

});

+0

爲什麼它不顯示在警告框中? –

+0

什麼顯示在警報框? –

+0

我對警報感到困擾(「<?php echo」this is pass「。$ pword?>」); –