gpt4 book ai didi

php - Mysqli 和绑定(bind)多个值

转载 作者:行者123 更新时间:2023-11-29 23:49:57 25 4
gpt4 key购买 nike

我真的不明白我做错了什么。代码根本不会写在表中

if (isset($_POST['submit']))
{
// get the form data
$name = htmlentities($_POST['name'], ENT_QUOTES);
$last = htmlentities($_POST['last'], ENT_QUOTES);
$date = htmlentities($_POST['date'], ENT_QUOTES);
$ran = htmlentities($_POST['ran'], ENT_QUOTES);

if ($name == '' || $last == '' || $date == '' || $ran == '')
{
// if they are empty, show an error message and display the form
$error = 'ERROR: Please fill in all required fields!';
renderForm($name, $last, $date, $ran, $error);
}
else
{
// insert the new record into the database
if ($stmt = $mysqli->prepare("INSERT users (name, last, date, ran) VALUES (?, ?, ?, ?)"))
{
$stmt->bind_param("ssss", $name, $last, $date, $ran);
$stmt->execute();
$stmt->close();
}
// show an error if the query has an error
else
{
echo "ERROR: Could not prepare SQL statement.";
}

// redirec the user
header("Location: view.php");
}

}
// if the form hasn't been submitted yet, show the form
else
{
renderForm();
}

// close the mysqli connection
$mysqli->close();
?>

我已经准备好了表格,如果我手动插入表格,它就可以工作(我有一个 View.php),但是当我运行表单时,什么也没有,没有错误,什么也没有!

最佳答案

已修复:

$stmt = $mysqli->prepare("INSERT INTO users (`name`,`last`,`date`,`ran`) VALUES (?, ?, ?, ?)");

关于php - Mysqli 和绑定(bind)多个值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25699438/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com