Question
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
************************************************************************************
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
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started