Jump to content

While Loop and cURL not working


xstevey_bx

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.