Iank1968 Posted March 7, 2009 Share Posted March 7, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/148325-getting-parse-error-syntax-error-unexpected-t_else-in/ Share on other sites More sharing options...
genericnumber1 Posted March 7, 2009 Share Posted March 7, 2009 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 { // ... Quote Link to comment https://forums.phpfreaks.com/topic/148325-getting-parse-error-syntax-error-unexpected-t_else-in/#findComment-778732 Share on other sites More sharing options...
Iank1968 Posted March 7, 2009 Author Share Posted March 7, 2009 so how do you recomend I clean up that code? Iam a newbie. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/148325-getting-parse-error-syntax-error-unexpected-t_else-in/#findComment-778738 Share on other sites More sharing options...
genericnumber1 Posted March 7, 2009 Share Posted March 7, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/148325-getting-parse-error-syntax-error-unexpected-t_else-in/#findComment-778739 Share on other sites More sharing options...
Iank1968 Posted March 7, 2009 Author Share Posted March 7, 2009 I took the else out and no im getting Parse error: syntax error, unexpected $end in /home/ianapps/public_html/globetrotters/common.php on line 2001 I have a ?> there thats the last line in the common.php file, what would that be? Quote Link to comment https://forums.phpfreaks.com/topic/148325-getting-parse-error-syntax-error-unexpected-t_else-in/#findComment-778741 Share on other sites More sharing options...
genericnumber1 Posted March 7, 2009 Share Posted March 7, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/148325-getting-parse-error-syntax-error-unexpected-t_else-in/#findComment-778742 Share on other sites More sharing options...
Iank1968 Posted March 7, 2009 Author Share Posted March 7, 2009 lol thats a new way of putting it. I will check all my {} and see where the missing one is. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/148325-getting-parse-error-syntax-error-unexpected-t_else-in/#findComment-778743 Share on other sites More sharing options...
Philip Posted March 7, 2009 Share Posted March 7, 2009 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); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/148325-getting-parse-error-syntax-error-unexpected-t_else-in/#findComment-778753 Share on other sites More sharing options...
genericnumber1 Posted March 7, 2009 Share Posted March 7, 2009 Pft, KP, always making me look like a jerk Quote Link to comment https://forums.phpfreaks.com/topic/148325-getting-parse-error-syntax-error-unexpected-t_else-in/#findComment-778758 Share on other sites More sharing options...
Philip Posted March 7, 2009 Share Posted March 7, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/148325-getting-parse-error-syntax-error-unexpected-t_else-in/#findComment-778762 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.