user51 Posted September 24, 2010 Share Posted September 24, 2010 hello, i am having a problem in my cron file that runs daily, the code posted below at the last block at the elseif ($chance > 2.5) <b>Parse error</b>: syntax error, unexpected T_ELSEIF in <b>/home/content/run_daily.php</b> on line <b>240</b><br /> ... $db = $dbh->prepare("select star_id from {$game}_stars where event_random = '6'"); $db->execute(); $bh_sys = $db->fetchrow_hashref(); if ($bh_sys) { $chance = rand(5); if ($chance < 1) { mysql_query("update {$game}_stars set event_random = 1, metal = '0', fuel='0', star_name = 'BlackHole' where star_id = '$bh_sys->{star_id}'"); mysql_query("insert into {$game}_news (timestamp, headline, login_id) values (".time().",'The <b>SuperNova Remnant</b> in <b class=b1>system $bh_sys->{star_id}</b> has formed into a <b>blackhole</b>. Being a slow process, all ships managed to get out to system #<b>1</b>. We expect no further trouble from that system. <font color=lime>- - - Science Institute of Sol - - -</font>','-11')"); $db = $dbh->prepare("select location,login_id,ship_id,ship_name from {$game}_ships where location = '$bh_sys->{star_id}'"); $db->execute(); while ($ship_bh = $db->fetchrow_hashref()) { mysql_query("update {$game}_ships set location = '1' where ship_id = '$ship_bh->{ship_id}'"); mysql_query("insert into {$game}_messages (timestamp,sender_name,sender_id, login_id, text) values(".time().",'BlackHole','$ship_bh->{login_id}','$ship_bh->{login_id}','Your ship the <b class=b1>$ship_bh->{ship_name}</b> escaped a blackhole forming from a SuperNova Remnant in system #<b>$ship_bh->{location}</b>. It is now in system #<b>1</b>')"); mysql_query("update {$game}_users set location = '1' where location = '$bh_sys->{star_id}'"); print "\nSN remnant in $bh_sys->{star_id} to blackhole\n"; } elseif ($chance > 2.5) { mysql_query("update {$game}_stars set event_random = '14' where star_id = '$bh_sys->{star_id}'"); mysql_query("insert into {$game}_news (timestamp, headline, login_id) values (".time().",'After much study, we have decided that the star in system <b>$bh_sys->{star_id}</b> will <b class=b1>not</b> become a Blackhole, as it was not massive enough. This system will remain a harmless Super-Nova Remnant, with lots of minerals in. <font color=lime>- - - Science Institute of Sol - - -</font>','-11')"); print "\nSN remnant in $bh_sys->{star_id} safe\n"; } } ... Help Quote Link to comment https://forums.phpfreaks.com/topic/214314-parse-error-syntax-error-unexpected-t_elseif/ Share on other sites More sharing options...
Maq Posted September 24, 2010 Share Posted September 24, 2010 You're missing closing braces. Quote Link to comment https://forums.phpfreaks.com/topic/214314-parse-error-syntax-error-unexpected-t_elseif/#findComment-1115263 Share on other sites More sharing options...
Pikachu2000 Posted September 24, 2010 Share Posted September 24, 2010 Your while() loop is unclosed. Quote Link to comment https://forums.phpfreaks.com/topic/214314-parse-error-syntax-error-unexpected-t_elseif/#findComment-1115264 Share on other sites More sharing options...
user51 Posted September 24, 2010 Author Share Posted September 24, 2010 i apreciate the responses, one more question, should i end the while loop before or after the else statement? i am also a little lost with the closing braces. i thought i placed two of them at the end of the block. Quote Link to comment https://forums.phpfreaks.com/topic/214314-parse-error-syntax-error-unexpected-t_elseif/#findComment-1115265 Share on other sites More sharing options...
Maq Posted September 24, 2010 Share Posted September 24, 2010 should i end the while loop before or after the else statement? Looks like before. i am also a little lost with the closing braces. i thought i placed two of them at the end of the block. Properly formatting your code makes these type of errors easy to detect and keep your code way more readable. Quote Link to comment https://forums.phpfreaks.com/topic/214314-parse-error-syntax-error-unexpected-t_elseif/#findComment-1115276 Share on other sites More sharing options...
user51 Posted September 24, 2010 Author Share Posted September 24, 2010 my apologies guys , now im getting and unexpected endwhile. im having a brainlock here. any pointers as of where to place these? Quote Link to comment https://forums.phpfreaks.com/topic/214314-parse-error-syntax-error-unexpected-t_elseif/#findComment-1115289 Share on other sites More sharing options...
Maq Posted September 24, 2010 Share Posted September 24, 2010 Can you post the current code inside tags? Quote Link to comment https://forums.phpfreaks.com/topic/214314-parse-error-syntax-error-unexpected-t_elseif/#findComment-1115297 Share on other sites More sharing options...
user51 Posted September 24, 2010 Author Share Posted September 24, 2010 I thank you all for helping me with your pointers, however it appears that the script wasnt happy with placing an, if, while, elseif comand in that order, i shuffeled them around, while, if, and modified the elseif to if, and that did the trick. now im getting a series of other errors but hey, debuging, and coffe.... right? lol again thank you guys. Quote Link to comment https://forums.phpfreaks.com/topic/214314-parse-error-syntax-error-unexpected-t_elseif/#findComment-1115303 Share on other sites More sharing options...
Maq Posted September 24, 2010 Share Posted September 24, 2010 There really shouldn't be a reason to have that order anyway. In an if/elseif you can only execute one of the blocks, so either put the while before or after that block. i shuffeled them around, while, if, and modified the elseif to if, and that did the trick. You should be able to keep the elseif if you moved the while before the blocks. Remember, 2 ifs aren't the same as if/elseif. Quote Link to comment https://forums.phpfreaks.com/topic/214314-parse-error-syntax-error-unexpected-t_elseif/#findComment-1115311 Share on other sites More sharing options...
user51 Posted September 24, 2010 Author Share Posted September 24, 2010 im attempting to translate this file to php from perl, the original cron file was written in perl. the original translator left the job in the middle and this block was smack in the middle of the cron file, disabling some aspects of the game. im not sure if the original cron file actually worked right, but im moving down block by block trying to debug. thats why the code is a little messy, i understand what youre saying, just logically the code didnt make sense separating an if and /or elseif with a while in the middle. Quote Link to comment https://forums.phpfreaks.com/topic/214314-parse-error-syntax-error-unexpected-t_elseif/#findComment-1115314 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.