Hello ! I came across a problem here and there are already similar solutions on the forum, but they did not help me, so I need to check for the login in the SQL table. Code: For variables that do not exist, do not pay attention, I cut the code.

elseif(isset($_POST["login"])) { $login = $_POST["login"]; $password = $_POST["password"]; $email = $_POST["email"]; mysqli_query($mysql_con, "INSERT INTO `users` (`id`, `login`, `password`, `email`, `IP`, `Browser`, `Date`, `City`) VALUES ('', '$login', '$password', '$email', '$ipaddress', '$browser', '$Date', '$result');"); 

As I saw on the forum there is a solution like

SELECT 'login' FROM 'users' WHERE' login '= "$ login';

But I do not quite understand, please tell me

    1 answer 1

    Before you write a new login to the table (by the way, the log field should be a unique index), you need to check whether such a login already exists in the table. To do this, you need to see whether the select will return the data:

     SELECT login FROM users WHERE login = $login; 

    If the select returned a non-empty data set, such a login is already in the database and you need to report this, for example, with an error.

    • Can you please write the code in more detail? - VIP300100
    • Here everything is perfectly painted php.net/manual/ru/mysqli.query.php Below there are a lot of examples - Skim
    • that is, mysqli_num_rows ($ result)> 0 - is the login? - VIP300100
    • @ VIP300100 yes, exactly like that - Skim
    • Help, I kind of did it here, but what I enter is the existing login, which is not available, is still not added to the table // REQUEST $ ifses = "SELECT 'login' FROM 'users' WHERE 'login' = '$ login'"; // test if (mysqli_num_rows ($ ifses) {// HAVE LOGIN echo "This user exists!";}} {{NOT HAVE LOGIN mysqli_query ($ mysql_con, "INSERT INTO users ( id , login , password , email , IP , Browser , Date , City VALUES ('', '$ login', '$ password', '$ email', '$ ipaddress', '$ browser', '$ Date', '$ result'); ") ;} - VIP300100