I am creating a signup registration to connect to the database record. Somehow instead it does not and when I inspect the element from the browser no error, but from the signup.php it goes through else check when there are no password match found.
<pre><?php
$showAlert = false;
$showError = false;
$exists=false;
if($_SERVER["REQUEST_METHOD"] == "POST") {
// Include file which makes the
// Database Connection.
include 'db_config.php';
$username = $_POST["username"];
$password = $_POST["password"];
$cpassword = $_POST["cpassword"];
$sql = "Select * from signup where username='$username'";
$result = mysqli_query($conn, $sql);
$num = mysqli_num_rows($result);
// This sql query is use to check if
// the username is already present
// or not in our Database
if($num == 0) {
if(($password == $cpassword) && $exists==false) {
$hash = password_hash($password,
PASSWORD_DEFAULT);
// Password Hashing is used here.
$sql = "INSERT INTO `signup` ( `username`,
`password`, `date`) VALUES ('$username',
'$hash', current_timestamp())";
$result = mysqli_query($conn, $sql);
if ($result) {
$showAlert = true;
}
}
else {
$showError = "Passwords do not match";
}
}// end if
if($num>0)
{
$exists="Username not available";
}
}//end if
?>
<?php
if($showAlert) {
echo ' <div class="alert alert-success
alert-dismissible fade show" role="alert">
Success! Your account is
now created and you can login.
<button type="button" class="close"
data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div> ';
}
if($showError) {
echo ' <div class="alert alert-danger
alert-dismissible fade show" role="alert">
Error! '. $showError.'
<button type="button" class="close"
data-dismiss="alert aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div> ';
}
if($exists) {
echo ' <div class="alert alert-danger
alert-dismissible fade show" role="alert">
Error! '. $exists.'
<button type="button" class="close"
data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div> ';
}
?>
// Front end using boostrap
<form action="signup.php" method="post" class="relative z-5 wow fadeInUp">
<div class="form-group relative mb-25 mb-sm-20">
<input type="text" class="form-control input-lg input-white shadow-5" id="username" placeholder="Username" name="username" required>
<i class="far fa-user transform-v-center"></i>
</div>
<div class="form-group relative mb-25 mb-sm-20">