Jump to content


Photo

Unexpected T_ELSE


  • Please log in to reply
2 replies to this topic

#1 JackJack

JackJack
  • Members
  • PipPipPip
  • Advanced Member
  • 38 posts

Posted 15 April 2006 - 06:34 PM

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


<? 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>


Thank You

JJ

#2 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,015 posts

Posted 15 April 2006 - 07:06 PM

If you check your opening and closing {} you have

while {

} else {

}

and not

if {
    while {

    }

} else {

And that's why you get the error
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#3 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 15 April 2006 - 07:18 PM

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:
<?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>
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.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users