第 27 行遇到问题,不太清楚为什么,因为我对 PHP/MySQL 很陌生。 想知道是否有人可以告诉我为什么我会收到错误;
"Fatal error: Call to a member function execute() on a non-object in C:\xampp\htdocs\testscripts\usercreate.php on line 27"
在以下代码中:
<?php
$name = $_POST["name"];
$psswrd = $_POST["psswrd"];
$username = "root";
$password = "hidden";
$hostname = "localhost";
$table = "testtable";
// create connection to database
// ...
$db= new mysqli($hostname, $username, $password, $table);
// sanitize the inputs
// ...
// create an MD5 hash of the password
$psswrd = md5($psswrd);
// save the values to the database
$sql = "INSERT INTO accounts (name, psswrd) VALUES (:name, :psswrd)";
$stmt = $db->prepare($sql);
$stmt->execute(array(
":name" => $name,
":psswrd" => $psswrd
));
最佳答案
如果发生错误,
->prepare
将返回 false
。由于 $stmt->execute
提示在非对象上调用,因此可以合理地假设查询出了问题。
检查$db->错误
。
关于php - 调用成员函数execute(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20760764/