Help, writes this error

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in Z:\home\php\www\save_user.php on line 156.

Here is half the code:

 $password = md5($password); $password = strrev($password); $password = $password."b3p6f"; include ("bd.php"); $result = mysql_query("SELECT id FROM users WHERE login='$login'",$db); $myrow = mysql_fetch_array($result); if (!empty($myrow['id'])) { exit ("Извините, введённый вами логин уже зарегистрирован. Введите другой логин."); } 

Reported as a duplicate by Athari , Yura Ivanov , Maxim Kamalov , ixSci , AntonioK May 16 '15 at 6:05 .

A similar question was asked earlier and an answer has already been received. If the answers provided are not exhaustive, please ask a new question .

    4 answers 4

    No result from the base.

     mysql_query("SELECT id FROM users WHERE login='$login'",$db) or die(mysql_error()); 

      Unable to perform an action in relation to the database table! Error crashes on

        $myrow = mysql_fetch_array($result); 

      because the connection failed ... You need to check the correctness of the connection to the database, the host, the password and the user, then, if everything is correct, you need to make sure that the user has enough rights to access the desired table (this is the most common error) and, finally , check the correctness of the "users" table name.

      • Here I have everything correctly written in phpmyadmin everything is correctly written the login password is everything, but now it writes "The database is not selected." What to do? - Anton
      • You need to select the mysql_select_db database ('database_name'); - johniek_comp
      • is it in quotes? - Anton

      No database selected writes this and I do not know what to do, but I connect like this <? Php $ db = mysql_connect ("localhost", "login name", "password"); mysql_select_db ("mysql", $ db); ?>

        You are returning 2 extra arrays! This is some kind of horror, there is another method to verify uniqueness.

         if(mysql_num_rows($result) > 0){ echo 'Такой логин занят'; } 

        and all!

         $myrow = mysql_fetch_array($result); if (!empty($myrow['id'])) { exit ("Извините, введённый вами логин уже зарегистрирован. Введите другой логин."); } 

        can be deleted