How check username and email already exists in php

How check username and email already exists in php . Below is what I am using-


$first = $_POST[‘first’];
$last = $_POST[‘last’];
$email = $_POST[‘email’];
$message = $_POST[‘message’];

date_default_timezone_set(‘Asia/Kolkata’);
$date=date(“d/m/Y h:i:sa”);

$sql = “INSERT INTO request (first,last,email,message,dt)
VALUES(’$first’,’$last’,’$email’,’$message’,’$date’)”;

if (mysqli_query($db, $sql)) {
echo “Request sent Sucessfully”;

  header ("Location: thankyou.html");

} else {
echo "Error: " . $sql . “
” . mysqli_error($db);
}
mysqli_close($db);

Any help please

Gary

You don’t. What you do is set a unique index on the DB columns, attempt the insert and catch the duplicate error if any.

Hi, Thanks I got it. Now need to try and display a error message on the form. Any help on this

Post your code attempt.

Sponsor our Newsletter | Privacy Policy | Terms of Service