So I'm just trying to make a simple sign up page, but no matter what I do I cant get the any of the information to be inserted into the database, can anyone see what I'm doing wrong?
There are no errors being thrown. And its also not directing me to the listings.php
page like I want it, rather, its just bringing me back to the index.php
page.
// include configuration file
include('config.php');
// connect to the database
$dbc = mysqli_connect ($db_host, $db_user, $db_password, $db_name) OR die ('Could not connect to MySQL: ' . mysqli_connect_error());
// continue session
session_start();
// if the form has been submitted
if(isset($_POST['submit']))
{
// create an empty error array
$error = array();
// check for a firstname
if(empty($_POST['firstname']))
{
$error['firstname'] = 'Required field';
}
// check for a lastname
if(empty($_POST['lastname']))
{
$error['lastname'] = 'Required field';
}
// check for a email
if(empty($_POST['email']))
{
$error['email'] = 'Required field';
} else {
// check to see if email address is unique
$query = "SELECT user_id FROM users WHERE email = '{$_POST['email']}'";
$result = mysqli_query($dbc, $query);
if(mysqli_num_rows($result) > 0)
{
$error['email'] = 'You already have an account';
}
}
// check for a password
if(empty($_POST['userpass']))
{
$error['userpass'] = 'Required field';
}
// if there are no errors
if(sizeof($error) == 0)
{
// insert user into the users table
"INSERT INTO users (
user_id,
firstname,
lastname,
email,
userpass,
signupdate
) VALUES (
null,
'{$_POST['firstname']}',
'{$_POST['lastname']}',
'{$_POST['email']}',
sha1('{$_POST['userpass']}'),
NOW()
)";
$result = mysqli_query($dbc, $query);
// obtain user_id from table
$user_id = mysqli_insert_id($dbc);
// send a signup e-mail to user
$message = "Dear {$_POST['firstname']} {$_POST['lastname']},\n";
$message = $message . "Thank you for signing up!\n";
mail($_POST['email'], 'Sign up confirmation', $message, "From: admin@designingsocialplatforms.com");
// append user_id to session array
$_SESSION['user_id'] = $user_id;
$_SESSION['firstname'] = $_POST['firstname'];
$_SESSION['lastname'] = $_POST['lastname'];
// redirect user to profile page
header("Location: listings.php");
exit();
}
}