我開發了一個用於登錄的登錄表單,但是當我嘗試登錄時它無法通過。以下是我使用的代碼的一部分。當我回顯$num
時,具有$num = mysql_num_rows()
的部分將返回零。這是爲什麼?看來我的INSERT
查詢沒有返回結果。請幫忙。用於登錄的MySql查詢不起作用
if ($warning==''){
$query="SELECT first_name FROM tblusers WHERE (email='$username') AND (password='".md5($_POST['password'])."')";
[email protected]_query($query);
$num = mysql_num_rows($result);
@mysql_close();
echo $num."perfecto".$result;
if($num==1)
{
$u=new User($username);
include ('includes/highlight.inc.php');
//insert user into session
if ($username=='admin'){
$_SESSION['user']=$username;
$p=new Page('Log In'.$username);
$p->setHeading('Welcome '.$u->getFirstName());
$p->setContent($cont."<br/><br/><br/> Use the administrator's panel on the right to do the administration work of the
website. To block and unblock users you use the <font color=red><b>View Auctions</b></font> link, and
that is when you can block the user after assessing their record.");
$p->printIt();
} else {
$_SESSION['user']=$username;
$p=new Page('Log In'.$username);
$p->setHeading('Welcome '.$u->getFirstName());
$p->setContent($cont."<br/><br/><br/>".$text);
$p->printIt(); }
}
檢查手冊查詢 –
你可以試試這個:SELECT first_name FROM tblusers WHERE email ='$ username'AND password ='md5($ _ POST ['password'])'作爲查詢 – Satya
執行'var_dump($ query );'在'SELECT'行下面,並將包含的變量與數據庫中的值進行比較。除此之外(與您的問題無關,mysql擴展在PHP 5.5.0以前不推薦使用,並且將來會被刪除,相反,應該使用MySQLi或PDO_MySQL擴展 – Bjoern