所以我搜遍了全部,并找到各种解决方案,只是不工作。PHP mySQL成功/失败重定向页面
我有一个注册页面,可以将数据插入到我的数据库中,该数据库可以正常工作。根据插入是否成功,我有一个if/else语句应该重定向到两个页面之一。现在它只是在表单提交后显示一个空白页面。
<?php
$hostname="xxxxxxxxxxxxxxxxxxxxx";
$username="xxxxxxxxxxxx";
$password="xxxxxxxxx";
$database="xxxxxxxxxxxxx";
$db = new mysqli($hostname, $username, $password, $database);
if ($db->connect_error){
die("Connection failed: " . $db->connect_error);
}
$pw = $_POST['pw'];
$UIN = $_POST['UIN'];
$sql = "INSERT INTO studentLogin (pw, UIN) VALUES ('$pw', '$UIN')";
if ($db->query($sql) === TRUE) {
header('Location: http://my_url/success.php.php?msg=WELCOME STUDENT');
exit();
} else {
header('Location: http://my_url/failure.php.php?msg=You must be a student to register for the student discussion page');
exit();
}
$db->close();
?>
首先,打开错误报告'<?php ini_set( 'display_errors',1);的error_reporting(-1)'。另外,您已经使用** MySQLi **,那么为什么不使用Prepared Statements来防止SQL注入?并且,什么是'failure.php.php',双扩展名.php.php? – Darren
您确定要重定向到有效的网址吗?此外,您正在严重冒SQL注入的风险。使用准备好的语句来防止它。 – miken32
我在想你可能在标题之前输出。 –