2010-09-18 97 views
0

可能重复:
mysql_fetch_array() expects parameter 1 to be resource, boolean given in selectPHP(MySQL的)错误: “警告:mysql_num_rows()预计参数1是资源”

if (!empty($_POST)){ 

    $email_to=$_POST['email_to']; 
    $email_to=mysql_real_escape_string($_POST['email_to']); 

    $sql = "UPDATE `cosmos`.`members` SET `conf` = '2' WHERE `members`.`email` = '$email_to';"; 
    $result=mysql_query($sql) or trigger_error(mysql_error().$sql); 

    $count=mysql_affected_rows($result);     // line 20 
    if($count==1){ 

    $rows=mysql_fetch_array($result); 
    $unique=$rows['u_code']; 
    $name=$rows['username']; 
    // ---------------- SEND MAIL FORM ---------------- 
    $to=$email_to; 
    $subject="Your Account Password Request! - Cosmos"; 
    $header="from: Tayal's/Cosmos <[email protected]>"; 
    $messages= "Hey $name ,\r\n"; 
    $messages.="You recently requested a new password"; 
    $messages.="<br /><a href='confirm.php?uid" . $unique . "'>Confirmation Link</a> \r\n"; 
    $sentmail = mail($to,$subject,$messages,$header); 
    echo $messages; 
    } else { 
    echo "Not found your email in our database"; 
    } 


} 

警告:mysql_affected_rows()函数需要参数1是资源,布尔在C:\ wamp \ www \ a \ l \ forget.php在线20给出

+1

''conf' = \'2 \''是个问题。整个字符串用双引号括起来,并且您正在转义单引号 - 这不是必需的。我相信MySQL实际上会收到查询中的\字符。这会导致SQL错误。除了2. 此外,即使您似乎在其中存储int,“conf”确实是varchar字段而不是int: – JAL 2010-09-18 15:46:46

+0

@亚历JL - 更新,但仍然有相同的错误!并且'conf'是一个int not varchar – 2010-09-18 15:58:13

+0

如果conf是一个int字段而不是一个varchar - 该值不应该在你的查询中引用。 – JAL 2010-09-18 18:10:04

回答

1
$result=mysql_query($sql); 

$result=mysql_query($sql) or trigger_error(mysql_error().$sql); 

并重新运行

然后

$email_to=$_POST['email_to']; 

$email_to=mysql_real_escape_string($_POST['email_to']); 

哦对了,还有也引述

+0

注意:您的SQL语法有错误;检查与您的MySQL服务器版本相对应的手册,以便在第1行的'\'2 \'WHERE'members'.'email' ='[email protected]'处使用正确的语法'UPDATE'cosmos'.'members' SET'conf' = \'2 \'WHERE'members'.'email' ='[email protected]'; – 2010-09-18 15:37:46

+1

@tunetosuraj似乎你以某种方式被添加到“大约2”。它应该只是conf ='2' – 2010-09-18 15:42:32

+0

上面的一个是固定的,但不是'警告:mysql_affected_rows()期望参数1是资源,在C:\ wamp \ www \ a \ l \ forget.php中给出布尔值 – 2010-09-18 15:44:16

0

您执行的SQL不是SELECT,因此没有行被返回!

+1

+1。相反,OP需要的是[mysql_affected_rows](http://www.php.net/manual/en/function.mysql-affected-rows.php)。 – casablanca 2010-09-18 15:34:10

+2

正确。但它不是唯一的问题,它的stil布尔值,而不是资源 – 2010-09-18 15:35:24

+0

确实,谢谢你的提示。 – fredley 2010-09-18 15:35:29

2

$resultfalse因为您的查询无效(有语法错误)。用途:

$sql = "UPDATE members SET conf=2 WHERE email = '$email_to';" 

(注意周围$email_to引号)

而且mysql_num_rows()应该只用于SELECT查询。对于UPDATEINSERTDELETE,请改为使用mysql_affected_rows()。最后,为了将来的参考,如果你的查询不起作用,打印错误和使用的SQL查询(比如Col Shrapnel的答案)。它会帮助你知道什么是错的。

+0

嘿,sql部分工作,但不是'mysql_affected_rows()' – 2010-09-18 15:41:30

+0

@tune什么不行? – NullUserException 2010-09-18 15:42:44

+0

仍然得到'警告:mysql_affected_rows()期望参数1是资源,在C:\ wamp \ www \ a \ l \ forget.php'中给出布尔值,重点在于'mysql_affected_rows()' – 2010-09-18 15:45:19

相关问题