我已经创建了一个注册表单,现在使用以下代码来显示表单完成时创建的LoginID。 以下代码导致“可捕获的致命错误:类mysqli_result的对象无法转换为字符串”。 我不确定为什么这样做。
$result = mysqli_query($con, "SELECT LoginID FROM User WHERE name='$nameFromForm' AND password='$pwd'"); echo $result;我也试过用
$sql = mysqli_query($con, "SELECT LoginID FROM User WHERE name='$nameFromForm' AND password='$pwd' AS '$login'"); $result = mysqli_query($con, $sql); echo $result->fetch_object()->$login;修复此问题,就像上面的错误所建议的那样,虽然它会导致错误“警告:mysqli_query()[function.mysqli-query]:空查询”
和
“致命错误:在非对象上调用成员函数fetch_object()”
关于这两条新线路。 我不确定我在哪里出错,我试图接收的数据是一个自动增量主键,如果它有任何影响。 我并不关心这个问题的安全性,因为它不需要安全,只需要工作。
谢谢
I have created a registration form and am now using the following code in order to display the LoginID that was created when the form was completed. The following code results in "Catchable fatal error: Object of class mysqli_result could not be converted to string in". I'm not sure why it is doing this.
$result = mysqli_query($con, "SELECT LoginID FROM User WHERE name='$nameFromForm' AND password='$pwd'"); echo $result;I have also tried using
$sql = mysqli_query($con, "SELECT LoginID FROM User WHERE name='$nameFromForm' AND password='$pwd' AS '$login'"); $result = mysqli_query($con, $sql); echo $result->fetch_object()->$login;to fix this problem as was suggested in regards to the above error although it results in the errors "Warning: mysqli_query() [function.mysqli-query]: Empty query in"
and
"Fatal error: Call to a member function fetch_object() on a non-object in "
in regards to the two new lines. I'm not sure where I'm going wrong with this, the data I am trying to recieve is an auto increment primary key if that has any impact. I'm not concerned about security of this as it doesn't need to be secure, just work.
Thanks
最满意答案
尝试这个,
$result = mysqli_query($con, "SELECT LoginID as login FROM User WHERE name='$nameFromForm' AND password='$pwd'"); $row = mysqli_fetch_array($result); echo $row['login'];Try this,
$result = mysqli_query($con, "SELECT LoginID as login FROM User WHERE name='$nameFromForm' AND password='$pwd'"); $row = mysqli_fetch_array($result); echo $row['login'];更多推荐
发布评论