JackJack Posted April 15, 2006 Share Posted April 15, 2006 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 YouJJ Quote Link to comment https://forums.phpfreaks.com/topic/7499-unexpected-t_else/ Share on other sites More sharing options...
Barand Posted April 15, 2006 Share Posted April 15, 2006 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 Quote Link to comment https://forums.phpfreaks.com/topic/7499-unexpected-t_else/#findComment-27308 Share on other sites More sharing options...
wildteen88 Posted April 15, 2006 Share Posted April 15, 2006 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]<?phpinclude ("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. Quote Link to comment https://forums.phpfreaks.com/topic/7499-unexpected-t_else/#findComment-27311 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.