I am building a login system for my website using mysql and php. I want to make sure that to users dont have the same username.
<?php
$servername = "xxxxxxxx";
$username = "xxxxxxx";
$password = "xxxxxxx";
$dbname = "users";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
//pulls variables from the html form
$username=$_POST['username'];
$password=$_POST['password'];
$email=$_POST['email'];
$fname=$_POST['fname'];
$lname=$_POST['lname'];
$date=$POST['date'];
//inserts
$sql = "INSERT INTO users (username, password, email, fname, lname, birthday)
VALUES ('$username', '$password', '$email', '$fname', '$lname', '$date')";
if ($conn->query($sql) === TRUE) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
$conn->close();
?>
I want to make it so if someone tries to create an account with the username "test123" and "test123" was already being used then a page would come up telling that person to choose a different username.