Jump to content

Archived

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

JackJack

Unexpected T_ELSE

Recommended Posts

This says "unexpected t_else on line 26" but i don't know whats wrong because it was just working before.


[code]
<? include ("header.php"); ?>
<?php if ($stat[company_status] == 1){ ?>
    <p>Your already in a company.</p>
  <? }else{ ?>
  <?php
if($join > 0){
?>
    <?php

    $companyssel = mysql_query("SELECT * FROM `companys` WHERE `id`=$join ");
    while ($companys = mysql_fetch_array($companyssel)) {
    ?>
    <p>Are you sure you want to join <b><?php echo $companys['name']; ?></b>?</p>
    
        <table width="25%" height="39" border="0" cellpadding="0" cellspacing="0">
          <tr>
            <th scope="row"><form method="post" action="join.php?join=<?php echo $companys[id]; ?>">
            <input type="submit" value="Yes" />
            </form>
            <form method="post" action="district.php">
              <input type="submit" value="No" />
              </form>
              </th>
          </tr>
        </table>
<? }else{ ?>
      <p>Error occurred. If this problem persists, please contact a developer.</p>
  <? } ?>
  <? } ?>
  <? } ?>

<p align="right">
  <input name="button2" type="button" onclick="history.back()" value="Back">
</p>
[/code]

Thank You

JJ

Share this post


Link to post
Share on other sites
If you check your opening and closing {} you have

[code]while {

} else {

}[/code]

and not

[code]if {
    while {

    }

} else {[/code]

And that's why you get the error

Share this post


Link to post
Share on other sites
The way in which you are coding PHP isn't the most efficent way. You open and close a PHP statement on virtually every line. This I would not recommend to do as it is waste of time. I would only recommend to go in and out of PHP when you want to echo out large blocks of HTML. Such as your table. Below is your code which has been slightly recoded syntax wise:
[code]<?php

include ("header.php");

if ($stat['company_status'] == 1)
{
    echo "<p>Your already in a company.</p>";
}
else
{
    if($join > 0)
    {
        $companyssel = mysql_query("SELECT * FROM `companys` WHERE `id`=$join ");

        while ($companys = mysql_fetch_array($companyssel))
        {
?>
    <p>Are you sure you want to join <b><?php echo $companys['name']; ?></b>?</p>

    <table width="25%" height="39" border="0" cellpadding="0" cellspacing="0">
      <tr>
        <th scope="row">
          <form method="post" action="join.php?join=<?php echo $companys['id']; ?>">
            <input type="submit" value="Yes" />
          </form>
          <form method="post" action="district.php">
            <input type="submit" value="No" />
            </form>
          </th>
        </tr>
      </table>
<?php
        } // this was the missing closing bracket
    }
    else
    {
        echo "<p>Error occurred. If this problem persists, please contact a developer.</p>";
    }
}
?>
<p align="right">
  <input name="button2" type="button" onclick="history.back()" value="Back">
</p>[/code]As you can see there is far less open and closing of PHP statements. I also indented your code too. This way it is easy to see that your { and } pair up easier. Every time you code an { you should indent it(about 4 spaces, you can do by hitting the Tab key (the one above Caps Lock)) by one. Then when you type } you de-indent it by one (backspace once or 4 times if you used spaces). Your code now "flows" enabling your code to be readable.

Share this post


Link to post
Share on other sites

×

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.