我收集了数据并创建了一个数组:
Array
(
[0] => Array
(
[id] => 1
[name] => Martin
[surname] => test
[email] => martin@gmail.com
[dob] => 2015-02-24
)
[1] => Array
(
[id] => 2
[name] => Kary
[surname] => paulman
[email] => kary@gmail.com
[dob] => 2015-06-26
)
)
我在这个数组中有多条记录。
我想将数组中的每一条记录发布到www.recieve.com,如果发布成功,则返回“true”响应,如果失败,则返回“false”。
我已经在互联网上进行了研究,但我甚至不知道从哪里开始。
到目前为止,我的代码看起来像这样(这只是针对数组):
$query = "SELECT * FROM applicants";
$result = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_assoc($result)){
$res[] = $row;
}
echo "<pre>"; print_r($res); echo "</pre>";
I have tryed this and it is not working :
//Build my array
$query = "SELECT * FROM applicants";
$result = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_assoc($result)){
$res[] = $row;
}
//URL to post to
$url = 'https://theurl.com?';
//url-ify the data for the POST
foreach($res as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
rtrim($fields_string, '&');
$ch = curl_init();
//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_POST, count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
//execute post
$result = curl_exec($ch);
//close connection
curl_close($ch);
cURL
。 - D4V1D