Question: I have the database already set up through a server and, is connecting, just having trouble registering or logging in.. -------------------------------------------------------------------------- register.php ************************************************************************************ Register Registration
I have the database already set up through a server and, is connecting, just having trouble registering or logging in..
--------------------------------------------------------------------------
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
************************************************************************************************
