Jump to content

Unexpected T_ELSE


JackJack

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
Link to comment
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.
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.