Question
My program will not register any user, it will direct to home page, but not output username or nothing to let you know which user
My program will not register any user, it will direct to home page, but not output username or nothing to let you know which user you are, and i believe my database table is empty, i know that it is connecting to the database, because i dont recieve a mysql connection error...but cant register to website i think their is a problem with checkloginandregistration.php
members.php
ID | Phone | Address | Education | |
---|---|---|---|---|
ID | Phone | Address | Education |
require_once('db.php');
$db_host = ('localhost');
if(isset($_POST['update']))
{
$id=$_POST['id'];
$phone = $_POST['phone'];
$address = $_POST['address'];
$email = $_POST['email'];
$education = $_POST['education'];
$sql = "update users SET phone='$phone', address='$address',email='$email',education='$education' where id=$id";
if (mysqli_query($db, $sql))
{
echo " Update is successful ";
echo " Phone : ".$phone." Address :".$address." Email : ".$email;
}
}
?>
--------------------------------------------------------
CheckLoginAndRegistration.php
-------------------------------------
error_reporting(E_ALL); require_once('db.php'); $db_host = ('localhost'); session_start(); $errors = array(); // 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']); $address = mysqli_real_escape_string($db, $_POST['address']); $phone = mysqli_real_escape_string($db, $_POST['phone']); $education = mysqli_real_escape_string($db, $_POST['education']); // 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) VALUES('$username', '$password', '$email', '$phone', '$address', , '$education')"; mysqli_query($db, $query); $_SESSION['username'] = $username; $_SESSION['success'] = "You are now logged in";
}
header('location: members.php'); // 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: members.php'); // direct to home page }else { array_push($errors, "Wrong username/password combination"); } echo(" "); // Added for line break. print_r($errors); // Will print all errors captured. }
}
?>
---------------------------------
registrationform.php
Registration Form
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started