This question already has an answer here:
这个问题在这里已有答案:
- mysql_fetch_array()/mysql_fetch_assoc()/mysql_fetch_row()/mysql_num_rows etc… expects parameter 1 to be resource 31 answers
mysql_fetch_array()/ mysql_fetch_assoc()/ mysql_fetch_row()/ mysql_num_rows等...期望参数1为资源31答案
Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in /home/elijahrx/public_html/User/register.php on line 33 Sorry, something wrong, please try later!
警告:mysql_num_rows()期望参数1是资源,第33行/home/elijahrx/public_html/User/register.php中给出的布尔值抱歉,有问题,请稍后再试!
/* Verfiy whether the user ID exists */
$qry1="SELECT userID FROM User_T WHERE userID='$userID'";
$result1=@mysql_query($qry1);
if (mysql_num_rows($result1)!=0)
{ echo "$userID exists, please try another userID<BR>"; }
else
{
$qry2="insert into User_T (userID, name, password)
values(\"$userID\",\"$name\",\"$password\")";
$result2=@mysql_query($qry2);
if($result2)
{echo "$userID has been successfully registered !"; }
else
{echo "Sorry, something wrong, please try later!"; }
2 个解决方案
#1
2
This line is failing:
这条线路失败了:
$result1=@mysql_query($qry1);
But you are missing out on any error messages because you are using error suppression. Change it to this to see if errors are displayed:
但是您错过了任何错误消息,因为您正在使用错误抑制。将其更改为此以查看是否显示错误:
$result1=mysql_query($qry1);
You can also use the mysql_error function to output errors form MySql:
您还可以使用mysql_error函数从MySql输出错误:
http://php.net/manual/en/function.mysql-error.php
Once you have solved the error with the query/connection, you're good to go.
一旦你用查询/连接解决了错误,你就可以了。
#2
0
As it is already suggested by many users, there is an error in your SQL query which forces mysql_query
function to return FALSE
instead of the resource
.
正如许多用户已经建议的那样,SQL查询中存在错误,这会导致mysql_query函数返回FALSE而不是资源。
Check if your code looks like in the example taken from this documentation: http://php.net/manual/en/function.mysql-num-rows.php
检查您的代码是否与本文档中的示例相似:http://php.net/manual/en/function.mysql-num-rows.php
<?php
$link = mysql_connect("localhost", "mysql_user", "mysql_password");
mysql_select_db("database", $link);
$result = mysql_query("SELECT * FROM table1", $link);
$num_rows = mysql_num_rows($result);
echo "$num_rows Rows\n";
?>
Probably the database is not selected or connection to the MySQL server could not be established.
可能未选择数据库或无法建立与MySQL服务器的连接。
Try adding the database name to the query, e.g.:
尝试将数据库名称添加到查询中,例如:
$qry1="SELECT userID FROM MYDATABASENAME.User_T WHERE userID='$userID'";
#1
2
This line is failing:
这条线路失败了:
$result1=@mysql_query($qry1);
But you are missing out on any error messages because you are using error suppression. Change it to this to see if errors are displayed:
但是您错过了任何错误消息,因为您正在使用错误抑制。将其更改为此以查看是否显示错误:
$result1=mysql_query($qry1);
You can also use the mysql_error function to output errors form MySql:
您还可以使用mysql_error函数从MySql输出错误:
http://php.net/manual/en/function.mysql-error.php
Once you have solved the error with the query/connection, you're good to go.
一旦你用查询/连接解决了错误,你就可以了。
#2
0
As it is already suggested by many users, there is an error in your SQL query which forces mysql_query
function to return FALSE
instead of the resource
.
正如许多用户已经建议的那样,SQL查询中存在错误,这会导致mysql_query函数返回FALSE而不是资源。
Check if your code looks like in the example taken from this documentation: http://php.net/manual/en/function.mysql-num-rows.php
检查您的代码是否与本文档中的示例相似:http://php.net/manual/en/function.mysql-num-rows.php
<?php
$link = mysql_connect("localhost", "mysql_user", "mysql_password");
mysql_select_db("database", $link);
$result = mysql_query("SELECT * FROM table1", $link);
$num_rows = mysql_num_rows($result);
echo "$num_rows Rows\n";
?>
Probably the database is not selected or connection to the MySQL server could not be established.
可能未选择数据库或无法建立与MySQL服务器的连接。
Try adding the database name to the query, e.g.:
尝试将数据库名称添加到查询中,例如:
$qry1="SELECT userID FROM MYDATABASENAME.User_T WHERE userID='$userID'";