dongshuo2752 2013-03-02 17:19
浏览 49

任何人都可以在这个php / mysql UPDATE代码中发现错误 - mysql_affected_rows()返回错误

I have this PHP code:

The first look up query-1 works fine.. BUT The second query2 works as well but mysql_affected_rows() doesnt tell me if the record has been updated, why?

thanks.


$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 ---

========================

The resulting output is:

 --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

i think, the warning is because query2 doesnt return a resource-id that is needed by mysqL_affected_rows().

  • both db and table are in utf8. what am i doing wrong ?
  • 写回答

2条回答 默认 最新

  • douli7841 2013-03-02 17:27
    关注

    Indeed, put the result of mysql_connect in mysql_affected_rows to eliminate the error message and get the actual affected number of rows.

    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题