I am trying to create a query with an if/else condition wherein after the user inputs then submits, I need to query first and check if it is already existing in the database, then there will be an error prompt but if it does not exist, it will proceed to inserting the data.
Is it possible using the if/else condition? Any suggestions will be accepted though.
$name = $_POST['first_name'];
$age = $_POST['age'];
$birthday = $_POST['birthdate'];
$info = "SELECT * FROM user_info WHERE name = $name";
$queryres = mysqli_query($conn,$info);
if(name != $name){ ///query to check if $name value exist in database
$sql = "INSERT INTO user (name, age, birthdate)
VALUES ('$name','$age', '$birthday')";
} else {
echo "Name already exist!";
}