在PHP中发生非对象错误时调用成员函数exec()

编程入门 行业动态 更新时间:2024-10-26 13:27:53
本文介绍了在PHP中发生非对象错误时调用成员函数exec()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 function add_member($idmembers, $firstname, $lastname, $email, $phone, $level, $password) { global $db; $query = "INSERT INTO members (idmembers, first, last, email, phone, level, password) VALUES ($idmembers, '$firstname', '$lastname', '$email', '$phone', '$level', '$password')"; var_dump($query); $db->exec($query); }

此代码为我提供了此错误和var转储中的信息:

This code gives me this error and information from the var dump:

string(224)"INSERT INTO成员(idmembers,first,last,email,电话,级别,密码)VALUES(,'Gina','Hill','hill@me','7778889898','m','803591803e3d6e646cd3ee4a35fee6dd')致命错误:在第26行的J:\ XAMPP \ htdocs \ WEBSITE \ register.php中以null调用成员函数exec()

string(224) "INSERT INTO members (idmembers, first, last, email, phone, level, password) VALUES (, 'Gina', 'Hill', 'hill@me', '7778889898', 'm', '803591803e3d6e646cd3ee4a35fee6dd')" Fatal error: Call to a member function exec() on null in J:\XAMPP\htdocs\WEBSITE\register.php on line 26

我已经检查过将查询添加到数据库中,以确保查询正常运行并且可以正常工作.

I've checked adding the query to the database to make sure the query is working and it works fine.

推荐答案

我怀疑 $ db 不是对象(如果它实际上不是NULL)或 $ db 没有名为 exec 的函数.

I suspect that $db is either not an object (if it's not actually NULL), or $db doesn't have a function named exec.

我建议您验证与数据库的连接是否成功,并确认 $ db 是连接对象.确认 exec 是该对象的有效函数.

I recommend you verify that your connection to the database is successful, and verify that $db is the connection object. Verify that exec is a valid function for the object.

此外,您的代码似乎容易受到 SQL注入的攻击.(我们看不到传递给函数的参数已被转义"以安全地包含在SQL文本中.)我们更希望看到具有 bind占位符<的准备好的语句/strong>.

Also, your code appears to be vulnerable to SQL Injection. (We don't see that the arguments passed to the function have been "escaped" to be safe for inclusion in SQL text.) We much prefer to see a prepared statements with bind placeholders.

更多推荐

在PHP中发生非对象错误时调用成员函数exec()

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

发布评论

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

>www.elefans.com

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