Jump to content

getting Parse error: syntax error, unexpected T_ELSE in..


Iank1968

Recommended Posts

Ian getting a Parse error: syntax error, unexpected T_ELSE in /home/ianapps/public_html/globetrotters/common.php on line 804

 

function HandleOutstandingSendSuccesses ($user) {
  global $logsend_table;
  global $facebook;
  global $db_to_desc_send;
  //$rx_money = false;
  $result = Query ("SELECT id,uid_from,what,amt FROM $logsend_table WHERE uid_to=$user and notified='0' and trade=0");
$num_rows = mysql_num_rows ($result);
for ($i=0; $i<$num_rows; $i++) {
 $uid_from = mysql_result ($result, $i, "uid_from");
 $what = mysql_result ($result, $i, "what");
 $amt = mysql_result ($result, $i, "amt");
 $id = mysql_result ($result, $i, "id");
try {
 $info = $facebook->api_client->users_getInfo ($uid_from, "name");
  } catch (FacebookRestClientException $e) {
  $info = "";
  }
  //$persons_name = $info[0]['name'];
  $persons_name = isset ($info[0]['name']) && $info[0]['name'] 
             != "" ? $info[0]['name'] : "Someone";
            if ($what == "money") {
   //$rx_money = true;
   $amt_f = sprintf ("%.2f", $amt/100);
  	 ?>
      <fb:success message="WOW!!!!  <?=$persons_name;?> just sent you $<?=$amt_f;?> airfarebucks!" /> 
  	 <?
  }
  else {
   $prize_f = $db_to_desc_send[$what];
   ?>
      <fb:success message="WOW!!!! <?=$persons_name;?> just sent you <?=$amt;?> of the following prize: <?=$prize_f;?>" /> 
   <?
  }
  Query ("UPDATE $logsend_table SET notified=1 where id=$id");
}
}
(line 804)  else {  <-------------------------***************line 804***********************
   $prize_f = $db_to_desc_send[$what];
   }
   ?>
      //$result_new = Query ("UPDATE $logsend_table SET notified='1' where uid_to=$user");
      }
      function HandleCoupons ($user) {
  global $users_table;
  $result = Query ("SELECT sum(coupon1) FROM $users_table WHERE uid=$user and coupon1_notified='0'");
  if (mysql_result ($result, 0) > 0) { 
 $result_new = Query ("UPDATE $users_table SET coupon1_notified='1' where uid=$user");
}
return mysql_result ($result, 0);
}

 

Can anyone see why I would be getting that error?

 

Thanks

This code is incredibly messy.. when auto-indentation can't clear much up you know you need to refactor.

 

That else isn't expected because it's outside of the function, localizing the problem you have...

 

<?php
function HandleOutstandingSendSuccesses ($user) {
    // ...
}
else {
    // ...

It's really messy, I'm afraid it's too late and I've had too long of a day to make myself bite the bullet and try to guess what's going on. It looks like you have that else a few lines up as well as at the position it's causing the error.

Unexpected end typically means there's an unbalanced set of brackets in your code (ie. more { than }) although it could mean other things. It's basically php's way of saying "wait, you weren't done saying something to me, I wasn't ready for you to stop," perhaps the computing equivalent of telling PHP a really elaborate joke and stopping before the punchline, disappointing PHP and causing it to throw a hissy fit and hold its breath until you finish what you started.

Can you post your current code?

 

Here's what I have for you, more organized IMO - also read the comment about the while loop, it should make your code easier ;)

 

<?php
function HandleOutstandingSendSuccesses ($user) {
global $logsend_table;
global $facebook;
global $db_to_desc_send;
//$rx_money = false;
$result = Query ("SELECT id,uid_from,what,amt FROM $logsend_table WHERE uid_to=$user and notified='0' and trade=0");
$num_rows = mysql_num_rows($result);

// Why not use mysql_fetch_assoc here instead of the for( ) loop?
// Below is an example:
/*
while($row = mysql_fetch_array($result)) {
	$uid_from = $row['uid_from'];
	$what = $row['what'];
	// ... etc
	// run your try/catch and messages
} // end loop for each row fetched
*/
for ($i=0; $i<$num_rows; $i++) {
	$uid_from = mysql_result($result, $i, "uid_from");
	$what = mysql_result($result, $i, "what");
	$amt = mysql_result($result, $i, "amt");
	$id = mysql_result($result, $i, "id");
	try {
		$info = $facebook->api_client->users_getInfo ($uid_from, "name");
	} catch (FacebookRestClientException $e) {
		$info = "";
	}
	//$persons_name = $info[0]['name'];
	$persons_name = isset ($info[0]['name']) && $info[0]['name'] 
             != "" ? $info[0]['name'] : "Someone";
	if ($what == "money") {
		//$rx_money = true;
		$amt_f = sprintf ("%.2f", $amt/100);
		?>
		<fb:success message="WOW!!!!  <?php echo $persons_name;?> just sent you $<?php echo $amt_f;?> airfarebucks!" /> 
		<?php
	} else {
		$prize_f = $db_to_desc_send[$what];
		?>
		<fb:success message="WOW!!!! <?=$persons_name;?> just sent you <?=$amt;?> of the following prize: <?=$prize_f;?>" /> 
		<?php
	}
	Query("UPDATE $logsend_table SET notified=1 where id=$id");
}
} // end function

function HandleCoupons ($user) {
global $users_table;
$result = Query ("SELECT sum(coupon1) FROM $users_table WHERE uid=$user and coupon1_notified='0'");
if(mysql_result($result, 0) > 0) { 
	$result_new = Query ("UPDATE $users_table SET coupon1_notified='1' where uid=$user");
}
return mysql_result($result, 0);
}
?>

Archived

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

×
×
  • 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.