哪位大神能來給我解決下使用者登入時訪問mysql的問題
看看下面的代碼哪裡錯了 為什麼運行不了?
session_start();
mysql_connect("localhost","root","11111111")
or die("無法串連資料庫,請重試");
mysql_select_db("manage")
or die("無法選擇資料庫,請重試");
$today=date("Y-m-d H:i:s");
$query=" select id
from usertbl
where id=$id and secret=$secret
/*從資料庫中搜尋和登入使用者相應的資料*/
";
$result=mysql_query($query);
$numrows=mysql_num_rows($result);
if($numrows==0){
/*驗證是否能找出相同資料的使用者,不能則未註冊*/
echo "非法使用者";
echo "請註冊先";
echo "重試";
}
else{
$row=mysql_fetch_array($result);
$id=$row[0];
$query="
update usertbl
set lastlogin=$today
where id=$id";
$result=mysql_query($query);
setcookie("usercookie", "歡迎你,$id");
/*這裡使用了cookie,以方便之後的頁面認證。
但我未開發完這一塊。希望有興趣的朋友指正*/
echo "登入成功";
echo "請進!";
}
?>
------解決思路----------------------
select id from usertbl where id=$id and secret=$secret
$id、$secret 是在哪裡賦值的?值為多少?
另外應用單引號括起
------解決思路----------------------
錯誤提示呢?沒錯誤提示怎麼看!
$query=" select id
from usertbl
where id=$id and secret=$secret
/*從資料庫中搜尋和登入使用者相應的資料*/
";
sql在寫的時候記得字串要加引號
------解決思路----------------------
這樣寫
$query=" select id
from usertbl
where id=$id and secret='$secret'";
/*這裡使用了cookie,以方便之後的頁面認證。
但我未開發完這一塊。希望有興趣的朋友指正*/
37行報錯是因為這一段注釋第一行前面有個全形空格