PHP error with mysql_num_rows



我有一个简单的表格,提交时应该计算表中已经与提交的值相同的行数。

我无法弄清楚为什么这会返回错误...有什么想法吗?

错误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();
您可以使用

它看到查询错误,因为查询错误仅显示此错误

$result = mysql_query($query) or die(mysql_error());
<?php
$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 COUNT(1) FROM users WHERE email = $useremail";
$result = mysql_query($query);
$array = mysql_fetch_array($result);
$whatYouWant = $array[0][0];
mysql_close();
?>

但费雯丽是对的,更喜欢PDO而不是mysql_*函数......

通常这意味着查询是错误的。尝试对字段使用反引号:

"SELECT * FROM `users` WHERE `email` = '$useremail'"

替换

$result = mysql_query($query);

$result = mysql_query($query, $con);

相关内容

  • 没有找到相关文章

最新更新