我为php应用程序构建了一个新的注册页面。处理用户注册页面。用户提交用户信息后,它不会重定向到“index.php”,而是重定向到空白页面。请
<?php
require 'database-config.php';
session_start();
$username = $_POST['username'];
$password = $_POST['password'];
$password = md5($password);
$user_access_level = $_POST['radios'];
$dt = date('d-m-Y');
$query = $dbh->prepare("SELECT * FROM users WHERE username=:username");
$query->execute(array(':username' => $username));
if($query != false){
while($q = $query -> fetch(PDO::FETCH_ASSOC)){
$error = '<br><div class="info">Sorry, the username <b>'.$username.'</b> is already in use. Please enter a different username of your choice to proceed. Thanks.</div><br>';
}
}
else {
$insert = $dbh->prepare('INSERT INTO users(username, password, user_access_level, date) VALUES(:username, :password, :user_access_level, :date)');
$insert->execute(array(':username'=>$username,':password'=>$password,':user_access_level'=>$user_access_level,':date'=>$dt));
if(insert!=false){
header("location: index.php");
}
else{
$error = '<br><div class="info">Sorry, your account could not be created at the moment. Please try again or contact the site admin to report this error if the problem persist. Thanks.</div><br>';
}
}
?>
答案 0 :(得分:1)
您遇到语法错误。您错过了$
=&gt;上的insert
$insert
:
// $insert, not insert
if(insert!=false){
header("location: index.php");
应该是:
if($insert!=false){
header("location: index.php");
// exit on header is best practice
exit;
}
开启ini_set('display_errors',1); error_reporting(E_ALL);
。您可能会遇到更多错误。如果您有错误,则会注意到此错误。