Jump to content

Archived

This topic is now archived and is closed to further replies.

xstevey_bx

While Loop and cURL not working

Recommended Posts

I have never used cURL before but I need to use it for developing a facebook application. What I am trying to do is create a status update scheduler. There are two tables in my database. One table has generic updates for each day of the week an the other had special events. My script checks the day, checks to see if there is a special event in the future on that day, and if there is reminds guests of the upcoming event. If there is no event it posts the generic status.

 

<?php 
include('config.php');

$result2 = mysql_query("select facebook_id,facebook_access_token from admin where username='users'");
$row = mysql_fetch_array($result2);
$facebook_id = $row['facebook_id'];
$facebook_access_token = $row['facebook_access_token'];

$day = date('N');

$result2 = mysql_query("select * from events where date > CURDATE() order by date ASC")
or die(mysql_error());

$num_rows = mysql_num_rows($result2);

if($num_rows == 0) {
$result2 = mysql_query("select * FROM alerts WHERE id='$day'")
or die(mysql_error());
$row1  = mysql_fetch_array($result2);
echo 'There are no events just alerts';
} else {
while($row = mysql_fetch_array($result2)){
	if(date('N',strtotime($row[date])) == $day) {

		$id = $row['id'];

		$result1 = mysql_query("SELECT * FROM events WHERE id = $id")
		or die(mysql_error());

		$row1  = mysql_fetch_array($result1);

	} else {
		$result1 = mysql_query("SELECT * FROM alerts WHERE id = $day")
		or die(mysql_error());
		$row1  = mysql_fetch_array($result1);

	}
}
}

$params = array('access_token' => $facebook_access_token, 
	'message' => $row1[alert_message],
	'name'=> $row1[alert_name],
	'caption' => $row1[alert_caption],
	'link' => $row1[alert_link],
	'description' => $row1[alert_description],
	'picture' => $row1[alert_picture]
	);

$url = "https://graph.facebook.com/$facebook_id/feed";
$ch = curl_init();
curl_setopt_array($ch, array(
CURLOPT_URL => $url,
CURLOPT_POSTFIELDS => $params,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_VERBOSE => true
));

$result = curl_exec($ch);

?>

 

The problem seems to be occurring when the While loop is accessed. I have used 'echo' to follow the variables through the script and it all seems to be working. However if I try and execute the cURL and the While Loop has run then it does not seem to work. I know the cURL part works becuase if the variables cause the first IF statement default to ELSE then it runs fine.

 

Any help would be GREATLY appreciated.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.