I want that if user enter same email or username already in db or even if they enter one not in db it show an alert on the same page with all the content but it is taking them to a new page and there is no content there the URL is same BTW
Php part
<?php
if(isset($_POST['submit'])){
require_once '_dbconnect.php';
function sanitizeUserInput($userInput)
{
global $conn;
}
# COLLECT POST VARIABLES
$username = sanitizeUserInput($_POST['signupusername']);
$useremail = sanitizeUserInput($_POST['signupemail']);
$password = sanitizeUserInput($_POST['signuppassword']);
$password = password_hash($pass, PASSWORD_BCRYPT);
$sqlToCheckUserEmailExists = $conn->query("SELECT * FROM Users WHERE user_email = '$useremail'");
$sqlTOCheckUsernameExists = $conn->query("SELECT * FROM Users WHERE user_name = '$username'");
if(!$sqlToCheckUserEmailExists || !$sqlTOCheckUsernameExists)
{
}
if ($doEmailExist != 0) {
$showError = "Email Is In Use";
echo '<div class="alert alert-danger d-flex align-items-center my-0" role="alert">
<svg class="bi flex-shrink-0 me-2" width="24" height="24" role="img" aria-label="Success:"><use xlink:href="#check-circle-fill"/></svg>
<div>
<strong>Email already in use pls use a new one</strong>
</div>
</div>';
}
elseif($doUsernameExist != 0)
{
$showError = "Username Is In Use";
echo '<div class="alert alert-danger d-flex align-items-center my-0" role="alert">
<svg class="bi flex-shrink-0 me-2" width="24" height="24" role="img" aria-label="Success:"><use xlink:href="#check-circle-fill"/></svg>
<div>
<strong>Username already in use pls use a new one</strong>
</div>
</div>';
}
else
{
$sqlToINsertUserIntoDatabase = $conn->query("INSERT INTO Users (sno, user_name, user_email, user_pass, user_date) VALUES(NULL, '$username', '$useremail', '$password', CURRENT_TIMESTAMP)");
if (!$sqlToINsertUserIntoDatabase)
{
echo "FAILED TO INSERT USER INTO DATABSE, HERE IS WHY<b>" . mysqli_error($conn) . "</b>";
}
else
{
echo '<div class="alert alert-success d-flex align-items-center my-0" role="alert">
<svg class="bi flex-shrink-0 me-2" width="24" height="24" role="img" aria-label="Success:"><use xlink:href="#check-circle-fill"/></svg>
<div>
<strong>Successfully Signed up you can now login.</strong>
</div>
</div>';
}
}
}
?>
{"html5":"htmlmixed","css":"css","javascript":"javascript","php":"php","python":"python","ruby":"ruby","lua":"text\/x-lua","bash":"text\/x-sh","go":"go","c":"text\/x-csrc","cpp":"text\/x-c++src","diff":"diff","latex":"stex","sql":"sql","xml":"xml","apl":"apl","asterisk":"asterisk","c_loadrunner":"text\/x-csrc","c_mac":"text\/x-csrc","coffeescript":"text\/x-coffeescript","csharp":"text\/x-csharp","d":"d","ecmascript":"javascript","erlang":"erlang","groovy":"text\/x-groovy","haskell":"text\/x-haskell","haxe":"text\/x-haxe","html4strict":"htmlmixed","java":"text\/x-java","java5":"text\/x-java","jquery":"javascript","mirc":"mirc","mysql":"sql","ocaml":"text\/x-ocaml","pascal":"text\/x-pascal","perl":"perl","perl6":"perl","plsql":"sql","properties":"text\/x-properties","q":"text\/x-q","scala":"scala","scheme":"text\/x-scheme","tcl":"text\/x-tcl","vb":"text\/x-vb","verilog":"text\/x-verilog","yaml":"text\/x-yaml","z80":"text\/x-z80"}