Here is a piece of code:

$T_registered_users = mysql_query("SELECT is_login FROM registered_users WHERE is_login = '$_POST[login]'", $db); $MT_registered_users = mysql_fetch_array($T_registered_users); if($MT_registered_users['is_login']) $error_login = 'Введеный логин уже зарегистрирован.'; 

It gives an error: Warning: mysql_fetch_array (): we have no result for the MySQL result resource in X: \ home \ ua-torrents.com \ www \ registration \ index.php on line 32

The question is what kind of error and why?

  • Oh God! ... is_login = '$ _POST [login]' - romeo
  • Why not just read the error message itself? It’s clearly written there that when calling the mysql_fetch_array () function, an incorrect argument was provided, or rather, not a mysql-resource. We pass to it the result of the function mysql_query (), which returns either a resource or FALSE, and once we get an error about the resource, it means that FALSE is returned. We look for an error in the syntax when calling the mysql_query function and find $ _POST [login] without apostrophes. Read the text of the error, it is often written there, what is wrong with you. Shl. And generally, use better mysqli or PDO. - Kaito

1 answer 1

Write variables in the same style:

 // before: $T_registered_users // after: $t_registered_users // best: $result 

At you mysql_query most likely returned false .

Verification required:

 if ($result === false) { echo mysql_error(); } 

Do not use the procedural approach to access the database, for deprecated . Read what is written in the red frame on of.sayte .

How correctly ( read "Why it is worth using PDO" ):

 $dbname = 'test'; $username = 'user'; $password = 'pass'; $table = 'registered_users'; $is_login = (int)$_POST['login']; // какого типа данные вы здесь ожидаете? try { //** Соединение с СУБД **// $pdo = new \PDO("mysql:host=localhost;dbname={$dbname};charset=utf8;", $username, $password); $pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION); //** exists **// $sql = "SELECT is_login FROM {$table} WHERE is_login = :is_login"; $statement = $pdo->prepare($sql); $statement->execute(array('is_login' => $is_login)); if ($statement->fetchColumn()) { $error_login = 'Введеный логин уже зарегистрирован.'; } } catch(\PDOException $e) { echo $e->getMessage(); // display error }