Search code examples
phpmysqlmysql-num-rows

PHP error with mysql_num_rows


I have a simple form which when submitted should count the number of rows in a table which already have the same value as that submitted.

I can't work out why this is returning an error... any ideas?

The error is Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in .../register.php on line 31

$con = mysql_connect("table","user","pass");
if (!$con)
      {
      die('Could not connect: ' . mysql_error());
      }
mysql_select_db("db", $con);    

function check_input($value, $quoteIt)
  {
      // Stripslashes
      if (get_magic_quotes_gpc())
      {
          $value = stripslashes($value);
      }
      // Quote if not a number
      if (is_null($value) || $value=="") {
         $value = 'NULL';
      } else if (!is_numeric($value) && $quoteIt == 1) {
         $value = "'" . mysql_real_escape_string($value) . "'";
      }

      return $value;
  }

$useremail = check_input($_POST['useremail'], 1);
// Check to see if email address already exists in USERS table
$query="SELECT * FROM users WHERE email = $useremail";
$result = mysql_query($query);
echo $query;
echo mysql_num_rows($result); //THIS IS LINE 31
mysql_close();

Solution

  • You can see your query error using this, because of query error only this error showing

    $result = mysql_query($query) or die(mysql_error());