hi:)
I want the script to check the db table to see if there is the same username as what the user has submit with the register form, then stop the script from registering, but if the user has submited a new username, then registering.
I think the script should chack db and store all usernames in Array, and then in the If part check the value of $username with all values of that Array but i don't know how to do that.
This is my script but it need to be edited:
$username = $_POST['username'];
$sql = ("SELECT Username FROM Users");
$result = $conn->query($sql);
foreach($result as $key => $row) {
$array = array($row['Username']);
}
if($row['Username'] != $username) {
include('connection.php');
$sql = "INSERT INTO Users (Username, Password)
VALUES ('$username', '$password')";
$conn->exec($sql);
}
Is this part correct?!
$array = array($row['Username']);
How should i edit this part?
if($row['Username'] != $username) {