Please anyone can help me.
I need to add an if statement to verify if a user already exists on a table. Can someone help me on this. Here is my code. The code below it work but it doesn't verifyed if a user already exists.
Thanks
<?php
/* Attempt MySQL server connection. Assuming you are running MySQL
server with default setting (user 'root' with no password) */
$link = mysqli_connect("localhost", "root", "password", "database");
// Check connection
if($link === false){
die("ERROR: Could not connect. " . mysqli_connect_error());
}
// Escape user inputs for security
$UserName = mysqli_real_escape_string($link, $_POST['UserName']);
$temppass = mysqli_real_escape_string($link, $_POST['temppass']);
// attempt insert query execution
$sql = "INSERT INTO user (UserName, temppass) VALUES ('$UserName', '$temppass')";
if(mysqli_query($link, $sql)){
echo "Records added successfully.";
} else{
echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
}
// close connection
mysqli_close($link);
?>