[英]PHP bind_param error
When I start my script this Error appears:当我启动我的脚本时,会出现此错误:
Fatal error: Call to a member function bind_param() on a non-object in /Applications/XAMPP/xamppfiles/htdocs/Jil/login_skript.php on line 16
致命错误:在第 16 行的 /Applications/XAMPP/xamppfiles/htdocs/Jil/login_skript.php 中的非对象上调用成员 function bind_param()
Here is the script:这是脚本:
$sql = "SELECT ID, vorname, nachname, username, email, passwort, profilBild, geschlecht, alter, wohnort, ueberSich FROM benutzer WHERE username LIKE '?' LIMIT 1;";
$stmt = $db->prepare($sql);
$stmt->bind_param("s", $username);
The problem is that 'alter' is a MySQL keyword.问题是“alter”是一个 MySQL 关键字。 Enclose all your field names (or at least just 'alter') in backticks to fix this.
将所有字段名称(或至少只是“alter”)括在反引号中以解决此问题。
Also, don't put quotes around the '?'s in a prepared statement.另外,不要在准备好的语句中的 '?' 周围加上引号。 They will be added for you.
它们将为您添加。
$sql = "SELECT `ID`, `vorname`, `nachname`, `username`, `email`, `passwort`, `profilBild`, `geschlecht`, `alter`, `wohnort`, `ueberSich` FROM `benutzer` WHERE `username` LIKE ? LIMIT 1;";
$stmt = $db->prepare($sql);
$stmt->bind_param("s", $username);
This occurs because your select statement is invalid and the prepare returns NULL.这是因为您的 select 语句无效并且准备返回 NULL。 You don't need the
'
around the ?
您不需要
'
周围的?
. . There may be other errors as well that you can see by calling
$db->error
可能还有其他错误,您可以通过调用
$db->error
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.