我真的不知道自己做错了什么。代码只是不会写在表中
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)但是当我运行表单时没有任何错误,没有错误!
答案 0 :(得分:0)
修正了它:
$stmt = $mysqli->prepare("INSERT INTO users (`name`,`last`,`date`,`ran`) VALUES (?, ?, ?, ?)");