我已经在同一个小问题上坐了 10 多个小时,所以是时候问 stackoverflow 了!我已连接到数据库,但是在调用 mysqli_stmt_bind_param 时,我得到“无效的对象或资源”。
我已经在控制台中尝试了插入语句,它工作正常..
<?php
$con=mysqli_connect("127.0.0.1:3306", "myUsername", "password");
mysqli_select_db($con, "webshop");
if (mysqli_connect_errno($con))
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$query= mysqli_stmt_init($con);
mysqli_stmt_prepare($query, "INSERT INTO user (name, email, hash, address, tel) VALUES (?, ?, ?, ?, ?)");
mysqli_stmt_bind_param($query, "ssssi", $name, $email, $hash, $address, $tel);
if(mysqli_stmt_execute($query))
{
mysqli_close($con);
}
?>
非常感谢您的帮助!