开始时sql语句为:`
$sql = "select * from blog_userinfo where userName = $userNmae";
开始想法是" "会识别变量,只要输入的用户名和数据库中userName值一样就可以,这时会发现无法查找到记录,使用echo $sql结果为select * from blog_userInfo where userName=lyz;这里就可以发现错误原因了,因为userName是String类型的,所以正确的sql语句应该为:
$sql = "select * from blog_userinfo where userName = '{$userNmae}'";
echo $sql语句结果为select * from blog_userInfo where userName=‘lyz’
正确查找到blog_userinfo表中userName='lyz’的记录。