2014-10-01 53 views
-2

當我填寫我的表單時,它會檢查文件,但它保持在那裏,並且不會繼續到下一個文件。我試圖迴應一些變量,並檢查我的數據庫是否一切正確,數據庫中的所有內容都是正確的,但一些它如何進一步發展。我使用的用戶名和密碼也存在於數據庫中。登錄時遇到問題,檢查後不想繼續

這是腳本檢查

<?php 
$host = "localhost"; 
$username = "root"; 
$password = "root"; 
$db_name = "vgv"; 
$tbl_name = "user"; 

$link = mysqli_connect($host, $username, $password, $db_name); 

$myusername = $_POST['myusername']; 
$mypassword = md5($_POST['mypassword']); 

$myusername = stripslashes($myusername); 
$mypassword = stripslashes($mypassword); 
$myusername = mysqli_real_escape_string($link, $myusername); 
$mypassword = mysqli_real_escape_string($link, $mypassword); 
$sql = "SELECT * FROM $tbl_name WHERE username = '$myusername' and password = '$mypassword'"; 
$result = mysqli_query($link, $sql); 

$count = mysqli_num_rows($result); 
    echo $count; 

if($count == 1){ 

session_register("myusername"); 
session_register("mypassword"); 
header("location:admin.php"); 

} 
else { 
echo "Username doesn't exist or your password is wrong"; 
} 
mysqli_close($link); 
?> 

這是我使用的形式。

<DOCTYPE!> 
<html> 
    <head> 
     <meta charset="utf-8"/> 
    </head> 
    <body> 
      <table> 
       <tr> 
        <form name="form1" method="post" action="checklogin.php"> 
         <td> 
          <table class="login"> 
           <tr> 

           </tr> 
           <tr> 
            <td width="78">Username</td> 
            <td width="6">:</td> 
            <td width="294"><input name="myusername" placeholder="username" type="text" id="myusername"></td> 
           </tr> 
           <tr> 
            <td>Password</td> 
            <td>:</td> 
            <td><input name="mypassword" placeholder="password" type="password" id="mypassword"></td> 
           </tr> 
           <tr> 
            <td>&nbsp;</td> 
            <td>&nbsp;</td> 
            <td><input type="submit" name="Submit" value="Login"></td> 
           </tr> 
          </table> 
         </td> 
        </form> 
       </tr> 
      </table> 
     </div> 
    </body> 
</html> 

提交後,我收到此錯誤信息

Warning: Cannot modify header information - headers already sent by (output started at /Users/user/Desktop/login/checklogin.php:28) in /Users/user/Desktop/login/checklogin.php on line 33 
+0

討論你不需要'在session_start();'?你確定使用'header'重定向嗎?每次提交表單時都會收到錯誤信息嗎? – 2014-10-01 08:47:49

+0

頁面不重定向到admin.php?您收到的任何錯誤消息? – TBI 2014-10-01 08:48:28

+0

我會檢查它 – 2014-10-01 08:59:40

回答

0

嘗試把ob_start();任何其他代碼之前。

<?php 

ob_start(); 

... 

如果它仍然不起作用,請確保您的header重定向之前沒有任何HTML實體。

0

這個問題基本上發生在你的會話有問題時檢查你的會話或者發佈會話代碼。

注: 對不起由於數量不足的聲譽我不能無法評論,所以我放在一邊一個答案框