简体   繁体   中英

PHP User Registration Page

I built a new registration page for a php app. Ths processes the user registration page. After user has submitted user information, it doesnt redirect to "index.php" but rather to a blank page. PLease

 <?php require 'database-config.php'; session_start(); $username = $_POST['username']; $password = $_POST['password']; $password = md5($password); $user_access_level = $_POST['radios']; $dt = date('dm-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>'; } } ?> 

You have a syntax error. You missing the $ on insert => $insert :

// $insert, not insert
if(insert!=false){
    header("location: index.php");

Should be:

if($insert!=false){
        header("location: index.php");
        // exit on header is best practice
        exit;
    }

Turn on ini_set('display_errors',1); error_reporting(E_ALL); ini_set('display_errors',1); error_reporting(E_ALL); . You may have more errors you are missing. This error would have been noted if you had errors on.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM