第 27 行遇到问题,不太清楚为什么,因为我对 PHP/MySQL 很陌生。想知道是否有人可以告诉我为什么我会收到错误;
“致命错误:在第 27 行调用 C:\xampp\htdocs\testscripts\usercreate.php 中非对象的成员函数 execute()”
在以下代码中:
<?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
));