我有这个 PHP 代码:
第一次查找 query-1 工作正常。但第二个 query2 工作正常,但 mysql_affected_rows() 没有告诉我记录是否已更新,为什么?
谢谢。
$uemail = 'driggg2@gmail.com';
$authkey = '2f4071bffda44aa30064364055687d13';
require_once ('./domainsiteconnect.php'); // Connect to the database.
if ( $uemail && $authkey)
{
echo "<br>--uemail: [$uemail] -- && -- [$authkey] --- ";
$query1 = "SELECT * FROM member WHERE email='$uemail' AND actkey='$authkey' AND status='pending' ";
$result1 = mysql_query ($query1);
$num1 = mysql_num_rows ($result1);
if ( $num1 == 1 ) // Exactly 1 rec found - Update member to verified.
{
echo '<br>+++ query1: successful +++>br>';
$status = 'verified';
$query2 = " UPDATE member SET status='$status' WHERE email='$uemail' "; //AND actkey='$authkey' ";
//- $query2 = " UPDATE member SET status='$status' WHERE email='$uemail' AND actkey='$authkey' ";
$result2 = mysql_query($query2);
$num2 = mysql_affected_rows($result2);
if ( $num2 ) // updated? - inform user
{
echo "<br>--$uemail updated to verified --";
}
else
echo "<br>--$uemail verfication [update] failed --";
$val1=mysql_errno();
$val2=mysql_error();
//--
echo '<br>['.$query2.']--<br>--['.$result2.']<br>val-1:'.$val1.'<br> val-2'.$val2;
}
} //-- eof. if auth/email flags ok ---
=========================
结果输出是:
--uemail: [driggg2@gmail.com] -- && -- [2f4071bffda44aa30064364055687d13] ---
+++ query1: successful +++>br>
Warning: mysql_affected_rows() expects parameter 1 to be resource, boolean given in /home/arif/public_html/amy/public/domainsite/verifyfirst.php on line 125
--driggg2@gmail.com verfication [update] failed --
[ UPDATE member SET status='verified' WHERE email='driggg2@gmail.com'; ]--
--[1]
val-1:0
val-2
我认为,警告是因为 query2 没有返回 mysql_affected_rows() 所需的资源 ID。
- db 和 table 都在 utf8 中。我究竟做错了什么 ?