mysql_fetch_array()期望参数1是资源,在[重复]中给出布尔值
This question already has an answer here:
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>
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());
The query has failed, and you are passing the "false" to the fetch. That can't be because of the or die; You are not showing the real code?
- Do not use the mysql_* function
- Put error_reporting on
- Build some error checking into your script.