Hey everyone, I'm working on a project that allows the user to register but am running into an issue where when the registration page is submitted the user receives a blank page and no confirmation(database record isn't entered). I've read and re-read the code and can't seem to find the issue. The only thing I can come up with is that I'm using incorrect syntax in the INSERT statement. Any help that can be offered would be greatly appreciated.
//begin registration page//
require('./includes/config.inc.php');
require(MYSQL);
$page_title = 'Registration';
include('./includes/header.html');
//adding form functionality//
require_once('./includes/form_functions.inc.php');
//reg_errors definition//
//array that stores the form errors//
$reg_errors = array();
//Checking for a form submission//
//Is Form Completely Filled Out?//
//First Name//
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
if (preg_match('/^[A-Z \'.-]{2,45}$/i', $_POST['first_name'])) {
$fn = escape_data($_POST['first_name'], $dbc);
} else {
$reg_errors['first_name'] = 'Please enter your first name!';
}
//Last Name//
if (preg_match('/^[A-Z \'.-]{2,45}$/i', $_POST['last_name'])) {
$ln = escape_data($_POST['last_name'], $dbc);
} else {
$reg_errors['last_name'] = 'Please enter your last name!';
}
//Username//
if (preg_match('/^[A-Z0-9]{2,45}$/i', $_POST['username'])) {
$u = escape_data($_POST['username'], $dbc);
} else {
$reg_errors['username'] = 'Please enter a desired name using only letters and numbers!';
}
//email//
if (filter_var($_POST['email'], FILTER_VALIDATE_EMAIL) === $_POST['email']) {
$e = escape_data($_POST['email'], $dbc);
} else {
$reg_errors['email'] = 'Please enter a valid email address!';
}
//password entered and does it match the verification//
if (preg_match('/^(\w*(?=\w*\d)(?=\w*[a-z])(?=\w*[A-Z])\w*){6,}$/', $_POST['pass1']) ) {
if ($_POST['pass1'] === $_POST['pass2']) {
$p = $_POST['pass1'];
} else {
$reg_errors['pass2'] = 'Your password did not match the confirmed password!';
}
} else {
$reg_errors['pass1'] = 'Please enter a valid password!';
}
//INSERT USER INTO DATABASE
if(empty($reg_errors)){
$q = "SELECT email, username FROM users WHERE email='$e' OR username='$u'";
$r = mysqli_query($dbc, $q);
$rows = mysqli_num_rows($r);
if ($rows === 0) {
$q = "INSERT INTO users (username, email, pass, first_name,
last_name, date_expires) VALUES ('$u', '$e', '". password_hash($p, PASSWORD_BCRYPT). "',
'$fn', '$ln', ADDDATE(NOW(), INTERVAL 1 MONTH)";
$r = mysqli_query($dbc, $q);
//If user is successfully registered
if(mysqli_affected_rows($dbc) === 1) {
echo '<div class="alert alert-success"><h3>Thank you for registering!</h3>
<p>Thank you for registering. You may now log in and access the your music theory lessons</p>
</div>';
include('./includes/footer.html');
exit();
} else {
trigger_error('You could not be registered due to a system error. We apologize for the inconvenience and are working to correct this error ASAP.');
}
//If USERNAME OR EMAIL IS ALREADY REGISTERED//
if($rows === 2){
$reg_errors['email']= 'This email address has alreadt been registered. If you have forgotten your password, use the link to the left to have your password sent to you.';
$reg_errors['username'] ='This username has already been registered. Please try another.';
} else {
$row = mysqli_fetch_array($r, MYSQLI_NUM);
if ( ($row[0] === $_POST['email']) && ($row[1] === $_POST['username'])) {
$reg_errors['email'] = 'This email address has already been registered. If you have forgotten your password, user the link to the left to have your password sent to you.';
$reg_errors['username'] = 'This username has already been registered with this email address. If you have forgotten your password, use the link to the left to have your password sent to you.';
} elseif ($row[0] === $_POST['email']) {$reg_errors['email'] = 'This email address has alreadt been registered. If you have forgotten your password, use the link to the left to have your password sent to you.';
} elseif ($row[1] === $_POST['username']) {$reg_errors['username'] = 'This username has already been registered. Please try another.';
}
}
}
}
}
?>