0
我真的不明白我做错了什么。该代码根本就没有在表中写Mysqli和绑定多个值
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->的execute()''回报TRUE'?否则,打印'$ stmt-> error' – 2014-09-06 10:53:27
你不会看到由于重定向导致的“无法绑定”错误,但是如果你有警告启用它会告诉你'无法发送头文件输出已经开始'尝试'ini_set ('display_errors',1); error_reporting(E_ALL);'在文件开头 – andrew 2014-09-06 10:54:47
警告:mysqli :: prepare():(42000/1064):你的SQL语法错误;请检查与您的MySQL服务器版本对应的手册,以便在第74行的第1行的'desc)VALUES(?,?,?,?)'旁使用正确的语法。 – Maverick 2014-09-06 11:11:17