Semeena Kabeer
Semeena Kabeer

Reputation: 149

multiple facebook posting using curl

i need to post multiple message to facebook wall from the mysql database. first i fetch the data from mysql and put it in while loop

while($row=mysql_fetch_array($result))
      {

$des=$row[1];
$purpose=$row[3];
$price_sale=$row[4];
$price_rent=$row[5];
$img="example.com/images".mysql_result($result,0,2);


  $attachment =  array(
    'access_token' => "$token",
    'message' => $des,
    'picture' => $img,
    'link' => "example.com"
    );

$ch = curl_init();
    curl_setopt($ch, CURLOPT_URL,'https://graph.facebook.com/xxxxxxxxxxx/feed');

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $attachment);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);  //to suppress the curl output 
$result = curl_exec($ch);
curl_close ($ch);


echo $result;

} 

the $result contain 3 records. But only post the first row. Plz give a solution for this

Upvotes: 0

Views: 286

Answers (1)

pckabeer
pckabeer

Reputation: 694

Try changing the name of the variable that accepts the curl output.You are using the same variable above.

   while($row=mysql_fetch_array($result))
          {

    $des=$row[1];
    $purpose=$row[3];
    $price_sale=$row[4];
    $price_rent=$row[5];
    $img="example.com/images".mysql_result($result,0,2);


      $attachment =  array(
        'access_token' => "$token",
        'message' => $des,
        'picture' => $img,
        'link' => "example.com"
        );

    $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL,'https://graph.facebook.com/xxxxxxxxxxx/feed');

    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $attachment);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);  //to suppress the curl output 
    $curlresult = curl_exec($ch);
    curl_close ($ch);


    echo $curlresult;

    } 

Upvotes: 1

Related Questions