I am currently developing a hotel reservation system. I've created a sign up and login page for the guest to make reservation. Ive tested my program and whenever I enter details for sign up process, it got successfully stored in the database. The problem now is that when I try to enter the same detail for login process, its not working. I feel like its not connected to the database but I don't know what I got wrong. The error that I get everytime I try to login is "incorrect id or password", eventhough Ive already stored the same details in database during signup process.
Please help me find the solution for this one. Below are my coding so far. Thank you.
*note: This project is done during online class so my groupmate and I have to do our parts and I am in charge of putting in all together. This part is my friend's. When she runs it on her computer, she can login successfully. I have already changed the database name to mine but its still seems like its not connected for some reason :/
<?php
$hostname = "localhost";
$username= "root";
$password = "";
$db_name = "project";
$connect = mysqli_connect($hostname, $username, $password, $db_name);
if (!$connect){
echo "Connection failed!";
}
?>
This is the login page. (File Name: custlogin.php)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset = "UTF-8">
<title> My First Web Page </title>
</head>
<style>
@import url('https://fonts.googleapis.com/css2?family=Poppins&display=swap');
body
{
font-family: Arial, Helvetica, sans-serif;
font-size: 15px;
background-attachment: fixed;
background-size: 100% 100%;
margin: 0;
padding: 0;
background-image: url('https://assets.hyatt.com/content/dam/hyatt/hyattdam/images/2019/06/25/1437/Grand-Hyatt-Seoul-P1448-Sofabed-Service.jpg/Grand-Hyatt-Seoul-P1448-Sofabed-Service.16x9.jpg?imwidth=1280');
background-repeat: no-repeat;
}
input[type=text], input[type=password]
{
width: 40%;
padding: 12px 20px;
margin: 8px 0;
border: 2px solid #ccc;
box-sizing: border-box;
}
button
{
background-color: black;
color: white;
font-family: 'Poppins', sans-serif;
font-size: 13px;
border: none;
cursor: pointer;
text-align : center;
width: 70px;
height:30px;
}
button: hover
{
opacity: 0.8;
}
.cancelbtn, .join
{
width: 70px;
height:30px;
text-align: center;
background-color: black;
color:white;
}
.container
{
margin-top: 110px;
padding: 30px;
background-color: white;
margin-left: 300px;
margin-right: 300px;
text-align:center;
background: rgba(211,211,211,0.6);
}
span. password
{
float: right;
padding-top: 16px;
}
/* Change styles for span and cancel button on extra small screens */
@media screen and (max-width: 300px) {
span.password {
display: block;
float: none;
}
.cancelbtn {
width: 100%;
}
* {
box-sizing: border-box;
}
/* Create two equal columns that floats next to each other */
.column {
float: left;
width: 70%;
padding: 10px;
}
/* Clear floats after the columns */
.row:after {
content: "";
display: table;
clear: both;
}
</style>
<body>
<div class="container">
<form action = "custlogin2.php" method="post">
<?php if (isset($_GET['error'])) { ?>
<p class="error"><?php echo $_GET['error']; ?></p>
<?php } ?>
<p style="text-decoration: underline;"><b>WELCOME TO SECRET MIRAGE HOTEL</b></p><br><br><br>
<b>Member Id</b><br>
<input type="text" placeholder="Enter Member Id" name="memberID" required><br>
<b>Password</b><br>
<input type="password" placeholder="Enter Password" name="password" required><br><br>
<br>
<button type="submit">Sign In</button>
</form> <br>
<button onclick="document.location='custsignup.php'" class="join" style="float:left; width: 90px;">Join Now</button>
<button onclick="document.location='project.php'" class="cancelbtn" style="float:right;">Cancel</button>
<br>
</div>
</body>
</html>
This one to check. (custlogin2.php)
<?php
session_start();
include "db_connect.php";
if (isset($_POST['memberID']) && isset($_POST['password'])) {
function validate($data){
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
$memberID = validate($_POST['memberID']);
$password = validate($_POST['password']);
// hashing the password
$password = md5($password);
$sql = "SELECT * FROM customer WHERE memberID='$memberID' AND password='$password'";
$result = mysqli_query($connect, $sql);
if (mysqli_num_rows($result) === 1) {
$row = mysqli_fetch_assoc($result);
if ($row['memberID'] === $memberID && $row['password'] === $password) {
$_SESSION['memberID'] = $row['memberID'];
$_SESSION['firstName'] = $row['firstName'];
$_SESSION['lastName'] = $row['lastName'];
$_SESSION['cust_email'] = $row['cust_email'];
$_SESSION['cust_Address'] = $row['cust_Address'];
header("Location: home2.php");
exit();
}else{
header("Location: custlogin.php?error=Incorect Id or Password");
exit();
}
}else{
header("Location: custlogin.php?error=Incorect Id or Password");
exit();
}
}else{
header("Location: custlogin.php");
exit();
}
?>
This the sign up form
<body>
<div class="container">
<form action="custsignup-check.php" method="post">
<?php if (isset($_GET['error'])) { ?>
<p class="error"><?php echo $_GET['error']; ?></p>
<?php } ?>
<?php if (isset($_GET['success'])) { ?>
<p class="success"><?php echo $_GET['success']; ?></p>
<?php } ?>
<div class="row">
<p style="font-size:18px; text-decoration:underline;"><b>Join Secret Mirage</b></p>
<div class="column">
<b>First Name</b><br>
<input type="text"
placeholder="Enter First Name"
name="firstName" required><br>
<b>Id Number</b><br>
<input type="text"
placeholder="Enter Id Number"
name="memberID" required><br>
<b>Password</b><br>
<input type="password"
placeholder="Enter Password"
name="password" required><br>
<b>Email</b><br>
<input type="text"
placeholder="Enter Email"
name="cust_email" required><br>
</div>
<div class="column">
<b>Last Name</b><br>
<input type="text"
placeholder="Enter Last Name"
name="lastName" required><br>
<b>Address</b><br>'
<input type="text"
placeholder="Enter Address"
name="cust_Address" required><br>
<b>Confirm Password</b><br>
<input type="password" placeholder="Confirm Password" name="re_password" required><br>
<p style="text-align:justify;">By signing up, I agree to Secret Mariage's Terms of Use and Secret Mariage Member
Terms and Conditions.<p>
</div>
</div>
<button type="submit">Join</button>
</form>
<button onclick="document.location='project.php'" class="cancelbtn">Cancel</button>
<button onclick="document.location='custlogin.php'" class="login">Login</button>
<br>
</div>
</body>
</html>
This is the sign up check.
<?php
session_start();
include "db_connect.php";
if (isset($_POST['memberID']) && isset($_POST['firstName'])
&& isset($_POST['lastName']) && isset($_POST['password'])
&& isset($_POST['cust_email']) && isset($_POST['cust_Address'])) {
function validate($data){
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
$memberID = validate($_POST['memberID']);
$firstName = validate($_POST['firstName']);
$lastName = validate($_POST['lastName']);
$password = validate($_POST['password']);
$re_password = validate($_POST['re_password']);
$cust_email = ($_POST['cust_email']);
$cust_Address = ($_POST['cust_Address']);
if($password !== $re_password){
header("Location: custsignup.php?error=The confirmation password does not match");
exit();
}
else{
// hashing the password
$password = md5($password);
$sql2 = "INSERT INTO customer(memberID, firstName, lastName, password, cust_email, cust_Address) VALUES('$memberID', '$firstName', '$lastName','$password', '$cust_email', '$cust_Address' )";
$result2 = mysqli_query($connect, $sql2);
if ($result2)
{
header("Location: custsignup.php?success=Your account has been created successfully");
exit();
}
else
{
header("Location: custsignup.php?error=unknown error occurred");
exit();
}
}
}else
{
header("Location: custsignup.php");
exit();
}