Question: Can someone help me figure out why my code isnt posting into my database. I have a login page and a register page where the

Can someone help me figure out why my code isnt posting into my database. I have a login page and a register page where the user can sign up. but for some odd reason my data isnt posting into my register page and my login page has no data to pull from my database to log the user in.

register.php

Student Register Form

Register Page

Already a member? Sign in

login.php

Animated login form

Login Page

Forgot your password?
Not yet a member? Sign up

server.php

// variable declaration $email=$_POST['email']; $password_1e=$_POST['password_1']; $password_2=$_POST['password_2']; $errors = array(); $_SESSION['success'] = "";

// connect to database $db = mysqli_connect('localhost', 'root', 'MONAMAKER', 'registration');

// REGISTER USER if (isset($_POST['reg_user'])) { // receive all input values from the form $email = mysqli_real_escape_string($db, $_POST['email']); $password_1 = mysqli_real_escape_string($db, $_POST['password_1']); $password_2 = mysqli_real_escape_string($db, $_POST['password_2']);

// form validation: ensure that the form is correctly filled if (empty($email)) { array_push($errors, "Email is required"); } if (empty($password_1)) { array_push($errors, "Password is required"); }

if ($password_1 != $password_2) { array_push($errors, "The two passwords do not match"); }

// register user if there are no errors in the form if (count($errors) == 0) { $password = md5($password_1);//encrypt the password before saving in the database $query = "INSERT INTO users (email, password_1,password_2) VALUES('$email', '$password_1','$password_2')"; mysqli_query($db, $query);

$_SESSION['email'] = $email; $_SESSION['success'] = "You are now logged in"; header('location: index.php'); }

} // LOGIN USER if (isset($_POST['login_user'])) { $email = mysqli_real_escape_string($db, $_POST['email']); $password_1 = mysqli_real_escape_string($db, $_POST['password_1']);

if (empty($email)) { array_push($errors, "Email is required"); } if (empty($password)) { array_push($errors, "Password is required"); }

if (count($errors) == 0) { $password = md5($password); $query = "SELECT * FROM users WHERE email='$email' AND password_1='$password_1'"; $results = mysqli_query($db, $query);

if (mysqli_num_rows($results) == 1) { $_SESSION['email'] = $email; $_SESSION['success'] = "You are now logged in"; header('location: index.php'); }else { array_push($errors, "Wrong email/password combination"); } } }

?>

index.php

if (!isset($_SESSION['email'])) { $_SESSION['msg'] = "You must log in first"; header('location: server.php'); }

if (isset($_GET['logout'])) { session_destroy(); unset($_SESSION['email']); header("location: server.php"); }

?> Home

Home Page

Welcome

logout='1'" style="color: red;">logout

errors.php

0) : ?>

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!