可捕获的致命错误:类mysqli

编程入门 行业动态 更新时间:2024-10-21 09:53:30
可捕获的致命错误:类mysqli_result的对象无法在注册时转换为字符串(Catchable fatal error: Object of class mysqli_result could not be converted to string in registration)

我已经创建了一个注册表单,现在使用以下代码来显示表单完成时创建的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'];

更多推荐

本文发布于:2023-04-28 02:32:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1329780.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:错误   mysqli

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!