2015-06-21 70 views
-1

如下所示,我有一個登錄頁面,根據結果返回索引。當我來到這個頁面時,它什麼都不做。會話等註冊和登錄,但我必須手動重新進入我的網頁?登錄頁面位置不起作用登錄時

<?php 
session_start(); 

include("connect_db.php"); 

$tbl_name="users"; 
$email=$_POST['email']; 
$pass=$_POST['pass']; 

$sql="SELECT * FROM $tbl_name WHERE email='$email' and pass='$pass'"; 
$result=mysql_query($sql); 
$count=mysql_num_rows($result); 

if($count==1){ 

while($row = mysql_fetch_array($result)) 

$username=$row['username']; 

$_SESSION['username']=$username; 


header('location: index.php?login=yes'); 

}else { 

header('location: index.php?login=no'); 

} 

?> 
+2

[簡單:'session_register'已被棄用(http://php.net/manual/en/function.session-register.php) - [看看你自己...](http://php.net/manual/en/function.error-reporting.php),你錯過了'while($ row = mysql_fetch_array($ result))的括號' *「親自看」*會被抓到。 –

+0

'session_register()'=> [Warning 這個函數自PHP 5.3.0開始已經被拒絕,並且從PHP 5.4.0開始移除。](http://php.net/manual/en/function.session- register.php) –

+0

session_register實際上並沒有爲表單做任何事情。謝謝 –

回答

0

嘗試如下:

<?php 
session_start(); 

include("connect_db.php"); 

$tbl_name="users"; 
$email=$_POST['email']; 
$pass=$_POST['pass']; 

$sql="SELECT * FROM $tbl_name WHERE email='$email' and pass='$pass'"; 
$result=mysql_query($sql); 
$count=mysql_num_rows($result); 

if($count==1) 
{ 
    while($row = mysql_fetch_array($result)) 
    { 
     $username=$row['username']; 
     $_SESSION['username']=$username; 
    } 
    header('location: index.php?login=yes'); 
} 
else { 
    header('location: index.php?login=no'); 
} 
?> 
+0

謝謝,但仍然只是一個空白的屏幕,我沒有改變標題爲文本,看看是否有任何其他問題,但文本顯示罰款。還有更多建議。 –

+1

什麼是寫在'include(「connect_db.php」);' – AnkiiG

+0

更新你的$ conn = mysql_connect($ dbservername,$ dbusername,dbpassword); '通過'$ conn = mysql_connect($ dbservername,$ dbusername,$ dbpassword);'然後運行。 – AnkiiG