[英]mysql - PHP select from table does not work
So I am trying to get the FirstName value based on the email and password provided by the user. 因此,我试图根据用户提供的电子邮件和密码来获取FirstName值。 But for some reason the code I have does not return anything.
但是由于某种原因,我拥有的代码未返回任何内容。 Can anybody help?
有人可以帮忙吗?
$sql_result = "SELECT FirstName FROM $tbl_name WHERE Email='$email' and Password='$mypassword' limit 1";
$res = mysql_query($sql_result);
$value = mysql_fetch_object($res);
$_SESSION['name']=$value['FirstName'];
I have also tried the code below but that didn't work either. 我也尝试了下面的代码,但是也没有用。
$_SESSION['name']=$value->FirstName;
$value = mysql_fetch_object($res);
^^^^^^^---- fetching an object
$_SESSION['name']=$value['FirstName'];
^^^^^^^^^---treating it like an array
Try mysql_fetch_assoc()
instead, so your $value
really is an array, or use $value->FirstName
and use it as the object it really is. 尝试使用
mysql_fetch_assoc()
,这样您的$value
确实是一个数组,或者使用$value->FirstName
并将其用作实际的对象。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.