Help me please. On the server detects an error. Here she is:

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in z:\home\synape\www\testreg.php on line 27 Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in z:\home\synape\www\testreg.php on line 45 Извините, введённый вами логин или пароль неверный." 

Here is half the code:

 include ("bd.php"); $ip=getenv("HTTP_X_FORWARDED_FOR"); if (empty($ip) || $ip=='unknown') { $ip=getenv("REMOTE_ADDR"); } mysql_query ("DELETE FROM oshibka WHERE UNIX_TIMESTAMP() - UNIX_TIMESTAMP(date) > 900"); $result = mysql_query("SELECT col FROM oshibka WHERE ip='$ip'",$db); $myrow = mysql_fetch_array($result); if ($myrow['col'] > 2) { exit ("Вы набрали логин или пароль неверно 3 раза. Подождите 15 минут до следующей попытки."); } $password = md5($password); $password = strrev($password); $password = $password."b3p6f"; $result = mysql_query("SELECT * FROM users WHERE login='$login' AND password='$password'",$db); $myrow = mysql_fetch_array($result); if (empty($myrow['id'])) { $select = mysql_query ("SELECT ip FROM oshibka WHERE ip='$ip'"); $tmp = mysql_fetch_row ($select); if ($ip == $tmp[0]) { $result52 = mysql_query("SELECT col FROM oshibka WHERE ip='$ip'",$db); $myrow52 = mysql_fetch_array($result52); $col = $myrow52[0] + 1; mysql_query ("UPDATE oshibka SET col=$col,date=NOW() WHERE ip='$ip'"); } 

And the error in the code is here:

$myrow= mysql_fetch_array($result); and $tmp= mysql_fetch_row($select);

  • one
    Show the connection to the database. - Deonis

2 answers 2

the $ db variable is not valid, most likely due to the fact that there was no connection to the database.

  • and what to do - Anton
  • check the connection to the database, and mysql_query () uses two parameters, the first line of the query, the second $ db, but not just the string, which can also cause this error. - FLK
  • @FLK, since when it’s impossible not to pass the query pointer? - Oleg Arkhipov
  • mysql_query ("DELETE FROM oshibka WHERE UNIX_TIMESTAMP () - UNIX_TIMESTAMP (date)> 900"); this is anton
  • @ anthon In the mysql database you created a table called oshibka? - LordySL

This script is taken from here . The script from this lesson has a lot of errors, but it will still work correctly if you bring it to mind. The author of the lesson made a huge mistake, without specifying in paragraph No. 4 what the table will be called. As follows from the code below the table name: oshibka. Perhaps this is the mistake. When you installed the server, did you really enter this particular data or are they taken from the example localhost, "user", "1234"?

  • one
    Kick in them there is the design of the code indenting, tear out the eye is called. Now I understand where people learn to make code. - ReinRaus
  • no, what you see in the code is my data, but the DB is called not oshibka, mysq is ant