【发布时间】:2014-03-08 16:59:32
【问题描述】:
由于某种原因,我被困在过去一年对我来说很简单的事情上。将数据插入数据库。今天,我一直在尝试解决这个问题,我似乎无法理解为什么stmt->execute() 返回错误?!即使我打开 PHP 和 MySQLI 错误,我也没有收到任何错误。这是我的代码:
else
{
// We are all good, lets enter this person into our DB
$CheckUser->close();
if ($insert_stmt = $mysqli->prepare("INSERT INTO users (name, email, country, region, city, address, password, salt) VALUES (?, ?, ?, ?, ?, ?, ?, ?)")) {
$insert_stmt->bind_param('ssssssss', $name, $email, $geoplugin->countryName, $geoplugin->regoin, $geoplugin->city, $address, $password, $random_salt);
if($insert_stmt->execute())
{
// Success, redirect the user to his page (Remember to login the user)
header("Location: dashboard.php");
}
else
{
// Something happened
echo "Something Happened";
}
}
}
在我的页面上,“发生了一些事情”正在回显。但是,如果我打开 MYSQLI 错误,那么我在提交后只会得到一个空白页面。我做错了什么???
【问题讨论】:
-
使用错误处理函数来显示错误消息,而不是显示信息量少得多的“发生了什么事”消息。还有“如果我打开 MYSQLI 错误”——你如何启用它们?
-
请详细说明“我打开 MYSQLI 错误”
-
请将 PDO 函数包装在 try...catch 中:
-
@YourCommonSense
mysqli_report(MYSQLI_REPORT_ALL);
标签: php mysql mysqli prepared-statement