【问题标题】:PHP Uncaught error - preventing MySQL InjectionPHP 未捕获错误 - 防止 MySQL 注入
【发布时间】:2018-12-15 19:19:19
【问题描述】:

我收到以下错误

Fatal error: Uncaught Error: Call to a member function bind_param() on boolean in /opt/lampp/htdocs/magic/client/edit-client.php:102 Stack trace: #0 {main} thrown in /opt/lampp/htdocs/magic/client/edit-client.php on line 102

请参阅下面的代码以了解第 102 行及其周围

 $stmt = $link->prepare("UPDATE users SET password = ?, notes = ?, url = ?, services = ?, status = ?, invoice = ?, pin = ?, agent_notes = ?, email = ?, phone = ?, WHERE id = ?");
  $stmt->bind_param("ssssssissii", trim($_POST['password']), trim($_POST['notes']), trim($_POST['url']), trim($_POST['services']), trim($_POST['status']), trim($_POST['invoice']), trim($_POST['pin']), trim($_POST['agent_notes']), trim($_POST['email']), trim($_POST['phone']), $_SESSION['client_id']);

我不会撒谎,整个$stmt->bind_param("ssssssissii" 也让我感到困惑,我得到字符串和整数,但我不确定我是否正确假设:

如果输入包含文本和数字,那么它应该是s 如果它是只有 数字,那么它应该是i - 这不正确吗?

提前感谢您的帮助。

【问题讨论】:

  • phone = ?,
  • 该错误表明问题不在绑定参数时,而是在准备查询时。来自数据库的错误信息是什么? (可能在$link->error 或类似的地方?)永远不要假设,始终检查实际错误。
  • @FunkFortyNiner - 已删除,现在收到此Parse error: syntax error, unexpected '$_SESSION' (T_VARIABLE), expecting ',' or ')' in /opt/lampp/htdocs/magic/client/edit-client.php on line 102
  • @David - 我在哪里可以从数据库中找到错误?
  • @Tom:如果这是 mysqli,请检查 $link->error。至于您遇到的新错误,请仔细检查您的 PHP 语法。

标签: php mysql session


【解决方案1】:

phone = ?,

感谢@FunkFortyNine 的回答。

【讨论】:

  • 这不应该是@FunkFortyNiner 的答案,它解释了为什么 SQL 中的尾随逗号会破坏语法,而不是 PHP 在大多数情况下乐意接受尾随逗号吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-01-24
  • 2016-08-25
  • 2016-09-21
  • 1970-01-01
  • 2018-03-23
  • 2019-04-20
  • 1970-01-01
相关资源
最近更新 更多