Home  >  Article  >  Backend Development  >  哪位大神能来给小弟我解决下用户登录时访问mysql的有关问题

哪位大神能来给小弟我解决下用户登录时访问mysql的有关问题

WBOY
WBOYOriginal
2016-06-13 12:18:24774browse

哪位大神能来给我解决下用户登录时访问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行报错是因为这一段注释第一行前面有个全角空格

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn