Php 卷曲柱,而
我希望下面这段代码从mysql表中选择2行数据,并将数据发布到URLPhp 卷曲柱,而,php,mysql,curl,Php,Mysql,Curl,我希望下面这段代码从mysql表中选择2行数据,并将数据发布到URL $qry = "SELECT id,email,forename,surname,ipaddress,optin_date,optin_url FROM $db_tble ORDER BY id ASC LIMIT 2"; $result = mysql_query($qry); $num = mysql_num_rows($result); if($result) { $OK = 1; /** start feed
$qry = "SELECT id,email,forename,surname,ipaddress,optin_date,optin_url FROM $db_tble ORDER BY id ASC LIMIT 2";
$result = mysql_query($qry);
$num = mysql_num_rows($result);
if($result)
{
$OK = 1;
/** start feed **/
//create array of data to be posted
while ($row = mysql_fetch_assoc($result))
{
// unset($post_items,$curl_connection,$result,$var,$info);
$n++;
$qry_id = $row["id"];
$post_data['u'] = $testfeed_user;
$post_data['p'] = $testfeed_pswd;
// Action data
$post_data['email'] = $row["email"];
$post_data['fname'] = $row["forename"];
$post_data['lname'] = $row["surname"];
$post_data['ip'] = $row["ipaddress"];
$post_data['date'] = $row["optin_date"];
$post_data['url'] = $row["optin_url"];
//traverse array and prepare data for posting (key1=value1)
foreach ( $post_data as $key => $value) {
$post_items[] = $key . '=' . $value;
}
//create the final string to be posted using implode()
$post_string = implode ('&', $post_items);
//create cURL connection
$curl_connection = curl_init($post_url);
//set options
// HTTP request method defaults to GET
curl_setopt($curl_connection, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($curl_connection, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");
curl_setopt($curl_connection, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl_connection, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl_connection, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curl_connection, CURLOPT_RETURNTRANSFER, 1);
//set data to be posted
curl_setopt($curl_connection, CURLOPT_POSTFIELDS, $post_string);
//perform our request
$result = curl_exec($curl_connection);
//close the connection
curl_close($curl_connection);
unset($post_string);
unset($post_data);
unset($post_items);
/** end feed **/
}
它失败,出现“PHP警告:mysql\u fetch\u assoc:supplied参数在…中不是有效的mysql结果资源”错误
这通常意味着查询有错误,但下面的代码适用于该查询。所以,一定是while循环中的某个东西打破了它,但我不知道是什么
// echo "Select OK!";
$qry = "SELECT id,email,forename,surname,ipaddress,optin_date,optin_url FROM $db_tble ORDER BY id ASC LIMIT 2";
$result = mysql_query($qry);
$num = mysql_num_rows($result);
if (mysql_num_rows($result) != 0)
{
$OK = 1;
/** start feed **/
//create array of data to be posted
// $post_data['u'] = $testfeed_user;
// $post_data['p'] = $testfeed_pswd;
while ($row = mysql_fetch_assoc($result))
{
$qry_id = $row["id"];
$post_data['u'] = $testfeed_user;
$post_data['p'] = $testfeed_pswd;
// Action data
$post_data['email'] = $row["email"];
$post_data['fname'] = $row["forename"];
$post_data['lname'] = $row["surname"];
$post_data['ip'] = $row["ipaddress"];
$post_data['date'] = $row["optin_date"];
$post_data['url'] = $row["optin_url
//traverse array and prepare data for posting (key1=value1)
foreach ( $post_data as $key => $value) {
$post_items[] = $key . '=' . $value;
}
//create the final string to be posted using implode()
$post_string = implode ('&', $post_items);
echo "id=" . $qry_id . " - " . $post_string . "<br /<br />";
unset($post_items);
}
}
在while循环中覆盖$result
我不知道为什么,因为你似乎不使用它。只需curl\u exec就足够了。在while循环中覆盖$result
我不知道为什么,因为你似乎不使用它。只要curl_exec就够了。谢谢,这就是问题所在。愚蠢的是,我将变量$result重新用于另一个目的,以错误捕获URL、HTTP响应和HTML内容的潜在问题。i、 e.从网站获得“同意”。谢谢,这就是问题所在。愚蠢的是,我将变量$result重新用于另一个目的,以错误捕获URL、HTTP响应和HTML内容的潜在问题。i、 e.从现场获得“同意”。
$result = curl_exec($curl_connection);