Reputation: 1
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('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>';
}
}
?>
Upvotes: 0
Views: 162
Reputation: 12505
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);
. You may have more errors you are missing. This error would have been noted if you had errors on.
Upvotes: 1