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

Link to comment
Share on other sites

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 {
    // ...

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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);
}
?>

Link to comment
Share on other sites

Haha, nahhhh :)

 

Btw, @OP: never use short tags (<?) - always use <?php. This will guarantee that your script will be [mostly] compatible across servers, as in PHP 5 the short tags are disabled by default and PHP 6+ they will be deprecated

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.