douken0530 2012-09-08 11:41
浏览 102
已采纳

mysql_fetch_array()期望参数1是资源,在[重复]中给出布尔值

I am not the first guy who is asking this question here but seriously, I tried possible duplicates before asking.

Here is my code: Updated

 foreach ($pieces as $v) {
        $get_user ="SELECT * from demo_user WHERE user_name ='$v'";
        $result = mysql_query($get_user);
        if (!$result) {
             die(mysql_error());
        }
        while($row = mysql_fetch_array($result))
        {
            $GLOBAL_REST_URL = "http://192.168.0.100:9000/meeting/";
            $part_name = $row['user_name'];
            $participant = array("email"=>$row['primary_email'],
                    "contact_no"=>$row['primary_mobile'],
                    "password"=>$attendee_password,
                    );

            $LOCAL_REST_URL = $GLOBAL_REST_URL .$mtngid.'/participant/'.$row['user_name'] ;

           $json_part = array2json($participant);
           $curl_handle=curl_init();
           curl_setopt($curl_handle,CURLOPT_URL,$LOCAL_REST_URL);
           curl_setopt($curl_handle,CURLOPT_CONNECTTIMEOUT,20);

           curl_setopt($curl_handle, CURLOPT_CUSTOMREQUEST, "POST");
           curl_setopt($curl_handle, CURLOPT_POSTFIELDS,$json_part);

           curl_setopt($curl_handle, CURLOPT_HTTPHEADER, $headers);
           curl_setopt($curl_handle,CURLOPT_RETURNTRANSFER,1);
           $buffer = curl_exec($curl_handle);
           curl_close($curl_handle);
           $getit_part =  json_decode($buffer, true);
           if ($getit_part['code'] == 200){
            $key = $getit_part['data'];

            $join_url = "http://192.168.0.100/UI/user/joinuser.php?meetingid=".$mtngid."&key=".$getit_part['data']; 
            $pr_mobile = $row['primary_mobile'];
            $pr_email = $row['primary_email'];
            $sql = "INSERT INTO demo_participant(name, 
                             meeting_id_id, 
                             password, 
                             user_view__url, 
                             `key`, 
                             contact_no,
                             email)
                        SELECT '$part_name', 
                               id, 
                               '$attendee_password',
                               '$join_url',
                                {$getit_part['data']},
                               '$pr_mobile',
                               '$pr_email'
                        FROM demo_meeting
                        WHERE meetingID = '$mtngid'";

            $result = mysql_query($sql) or die (mysql_error());
           }
          // $message = 'Hi '.$_GET['meeting_name'].',and associated participant Updated successfully ';
        }
        }

When I execute the above code, I get the following warning:

mysql_fetch_array() expects parameter 1 to be resource, boolean given in

print_r($pieces) outputs:

Array
(
    [0] => Digvijay
    [1] => philip
    [2] => fake
)

Please let me know, what I might be doing wrong.

</div>
  • 写回答

2条回答 默认 最新

  • dongmou2389 2012-09-08 11:52
    关注

    With your code, $result won't be a boolean.

    if mysql_query return false, then the program should exit.

    Check the error line once more.

    Update:

    After reading your updated code, the problem is the line below (at the end of the while loop):

    $result = mysql_query($sql) or die (mysql_error());
    

    You are overwriting the variable $result.

    It is an insert query, so you only need to do:

    mysql_query($sql) or die (mysql_error());
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题
  • ¥15 Python时间序列如何拟合疏系数模型
  • ¥15 求学软件的前人们指明方向🥺
  • ¥50 如何增强飞上天的树莓派的热点信号强度,以使得笔记本可以在地面实现远程桌面连接
  • ¥20 双层网络上信息-疾病传播
  • ¥50 paddlepaddle pinn
  • ¥20 idea运行测试代码报错问题