Jump to content

Parse error: syntax error, unexpected T_ELSEIF


Recommended Posts

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  :(

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.

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.

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.

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.

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.