Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I am having trouble logging in and registering, was wondering if someone sees an error in my members.php, i have the database already set up.

I am having trouble logging in and registering, was wondering if someone sees an error in my members.php, i have the database already set up. My register page wont register user, it will just redirect you to homepage. and my log in page does not work, something wrong with my members.php.

-------------------------------------------------------------------------

register.php

************************************************************************************

Register

Registration

********************************************************************************************************

members.php

********************************************************************************************************

require_once('db.php');

session_start();

// REGISTER USER

if (isset($_POST['signup'])) {

// receive all input values from the form

$username = mysqli_real_escape_string($db, $_POST['username']);

$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($username)) { array_push($errors, "Username 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");

}

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

if (empty($phone)) { array_push($errors, "Phone is required"); }

if (empty($address)) { array_push($errors, "Address is required"); }

if (empty($education)) { array_push($errors, "Education is required"); }

// 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 (username, password, email, phone, address, education, state)

VALUES('$username', '$password', '$email', '$phone', '$address', , '$education')";

mysqli_query($db, $query);

$_SESSION['username'] = $username;

$_SESSION['success'] = "You are now logged in";

}

header('location: default.html'); // redirect after registering to homepage

}

// Login user

if (isset($_POST['login'])) {

$username = mysqli_real_escape_string($db, $_POST['username']);

$password = mysqli_real_escape_string($db, $_POST['password']);

if (empty($username)) {

array_push($errors, "Username is required");

}

if (empty($password)) {

array_push($errors, "Password is required");

}

if (count($errors) == 0) {

$password = md5($password);

$query = "SELECT * FROM users WHERE username='$username' AND password='$password'";

$results = mysqli_query($db, $query);

if (mysqli_num_rows($results) == 1) {

$_SESSION['username'] = $username;

$_SESSION['success'] = "You are now logged in";

header('location: default.html'); // direct to home page

}else {

array_push($errors, "Wrong username/password combination");

}

}

}

?>

**********************************************************************************************

LoginPage.php

************************************************************************************************

Login Form

Remember me

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Driven Web Sites

Authors: Mike Morrison, Joline Morrison

1st Edition

061901556X, 978-0619015565

More Books

Students also viewed these Databases questions

Question

6. Conclusion:

Answered: 1 week ago