morrisjohnny Posted December 1, 2007 Share Posted December 1, 2007 Hello I have one to many } in my PHP code i believe i've looked and looked but i can't find it. Can anyone find it?I've even tried to arrange it nice and more readableAny-one got any tips how to get out of this habbit?Error i getParse error: syntax error, unexpected T_ELSE in C:\xampp\htdocs\Games\Tycoon\office_cities.php on line 102This means i have too many }'s right? <?phpinclude ("Settings/__logincheck__.php"); if ($logged_in) {if (isset($_GET['q'])){ if (isset($_POST['build'])) { $db=mysql_connect($main_hostname, $main_username, $main_password); mysql_select_db($main_databse, $db); $result = mysql_query("SELECT * FROM $player_stock WHERE ID='$_SESSION[ID]"); $row = mysql_fetch_array($result); $wood=$row['Wood']; $steel=$row['Steel']; $brick=$row['Brick']; if ($wood>="100") { if ($steel>="100") { if ($brick>="10000") { $result = mysql_query("SELECT * FROM users_build WHERE playerID='$_SESSION[ID]' ORDER BY BuildingNo DESC"); $row = mysql_fetch_array($result); $newno=$row['BuildingNo']; if ($newno=="") { $newno="1"; } else { $newno++; } $nsteel==$steel-"100"; $nwood==$wood-"100"; $nbricks==$brick-"10000"; $sql="INSERT INTO $main_ubuild (CityID, PlayerID, BuildingID, BuildingNo, Upgrades) VALUES ('$_GET[q]','$_SESSION[ID]','$_POST[build]','$newno','')"; if (!mysql_query($sql,$db)) { $rmsga="<font color='red'>Error</font>";$rmsgb="<font color='red'>Sorry their was an error with subbmitting your data to the database</font>";$rmsgc="Please Go Back And Try again & Report the problem"; mysql_query("UPDATE $player_stock SET Wood='$nwood' AND Steel='$nsteel' AND Bricks='$nbricks' WHERE ID='$_SESSION[ID]'"); } else { $rmsga="<font color='green'>Sucess</font>";$rmsgb="<font color='green'>Congraulations, Your buildings has been built</font>";$rmsgc="<a href=\"office_build.php\">Click Here To View Your Buildings</a>"; } } else { $rmsga="<font color='red'>Not Enough Materials</font>";$rmsgb="<font color='red'>Sorry you do not have brick</font>";$rmsgc="Please gather more bricks and try again"; } } else { $rmsga="<font color='red'>Not Enough Materials</font>";$rmsgb="<font color='red'>Sorry you do not have steel</font>";$rmsgc="Please gather more steel and try again"; } } else { $rmsga="<font color='red'>Not Enough Materials</font>";$rmsgb="<font color='red'>Sorry you do not have Wood</font>";$rmsgc="Please gather more Wood and try again"; } echo"<table align='center' width='55%' class='tablemain'> <tr><td class='header'><strong>".$rmsga."</strong></td></tr> <tr><td>".$rmsgb."</td></tr> <tr><td>".$rmsgc."</td></tr> </table>"; } else { /*$_GET['q'] Is set but not $_POST['Build']*/ $q=$_GET['q']; $db=mysql_connect($main_hostname, $main_username, $main_password); mysql_select_db($main_databse, $db); $result = mysql_query("SELECT * FROM $main_cities WHERE ID='$q'"); echo"<table class=\"tablemain\" align=\"center\" border=\"0\">"; while($row = mysql_fetch_array($result)) { echo "<tr><td colspan=\"2\" class=\"header\"><strong>".$row['Name'] . "</strong></td></tr>"; echo "<tr><td>Region</td><td>".$row['Region']."</td></tr>"; echo "<tr><td>Population</td><td>".$row['Population']."</td></tr>"; echo "<tr><td colspan=\"2\"><strong>Regulations</strong></td></tr>"; echo "<tr><td colspan=\"2\">"; $string = $row['modifiers']; $var = explode("\n",$string); $value="0"; while(isset($var[$value])) { echo $var[$value].", "; $value++; } echo "</td></tr>"; } echo"<tr><td colspan=\"2\" align=\"center\"><a href=\"office_cities.php\">Back To All Cities</a></td></tr></table> <table class=\"tablemain\" align=\"center\" border=\"0\"><tr><td><form action='' method='post'>Building:<select name='build'>"; $result2 = mysql_query("SELECT * FROM $main_dbuild"); while($rowa = mysql_fetch_array($result2)) { echo "<option value=\"".$rowa['Name']."\">".$rowa['Name']."</option>"; } echo"</select></td></tr><td><input type='submit' /></form></tr></table>"; }else{/*$_GET['q'] Is not set*/ echo"</head> <body> <table class=\"tablemain\" align=\"center\" width=\"500\"> <tr><td class=\"header\" colspan=\"3\"><b>Cities Aviable</b></td></tr> <tr><td><strong>Name</strong></td><td><strong>Population</strong></td><td><strong>Region</strong></td></tr>"; $db=mysql_connect($main_hostname, $main_username, $main_password); mysql_select_db($main_databse, $db); $result = mysql_query("SELECT * FROM $main_cities"); while($row = mysql_fetch_array($result)) { echo "<tr><td><a href=\"office_cities.php?q=".$row['ID']."\">".$row['Name']."</td><td>".$row['Population']."</td><td>".$row['Region']."</td></tr>"; } "</table> </body> </html>";}else{include("log_in.php");}?> Link to comment Share on other sites More sharing options...
zppblood Posted December 1, 2007 Share Posted December 1, 2007 I don't know if this is it, but try adding another } at the end. Link to comment Share on other sites More sharing options...
Ingolme Posted December 1, 2007 Share Posted December 1, 2007 Yes, somewhere or another you must have added at least one extra } Link to comment Share on other sites More sharing options...
coolgamer48 Posted December 2, 2007 Share Posted December 2, 2007 The error is on (or near) line 102. I would look there.If you're using regular notepad for your editing, I HIGHLY suggest getting Notepad++ (Google it) or some other specialized coding program. It makes problems like these a lot easier to solve. Link to comment Share on other sites More sharing options...
justsomeguy Posted December 3, 2007 Share Posted December 3, 2007 This:if (isset($_GET['q'])){Is missing a closing }. It should be before the else on line 102. If you load the source into a text editor like ConTEXT you can highlight the matching braces or jump to the matching brace. It makes figuring out the structure of the file a little easier. Link to comment Share on other sites More sharing options...
morrisjohnny Posted December 4, 2007 Author Share Posted December 4, 2007 when i add a new } i get this errori want an else statement for if (isset($_GET['q'])){after echo "<option value=\"".$rowa['Name']."\">".$rowa['Name']."</option>"; } echo"</select></td></tr><td><input type='submit' /></form></tr></table>"; }but it's their ! so i've midde it out somewhere else but i really cn't find where anyone massive help? Link to comment Share on other sites More sharing options...
justsomeguy Posted December 4, 2007 Share Posted December 4, 2007 I didn't understand your last post at all, but if you add a } above the else on line 102 of your original code it will work. You can't just add a } just any old place in the file and expect it to work, there is a single, specific place where it needs to be added (before the else statement that is supposed to correspond to the if). Link to comment Share on other sites More sharing options...
morrisjohnny Posted December 4, 2007 Author Share Posted December 4, 2007 their is no else on line 102 and i've check even reformatted it in line breaks indenting when a new bloc of code starts and ends with {} and i still get it even i'm getting this while($row = mysql_fetch_array($result)) { echo "<tr><td colspan=\"2\" class=\"header\"><strong>".$row['Name'] . "</strong></td></tr>"; echo "<tr><td>Region</td><td>".$row['Region']."</td></tr>"; echo "<tr><td>Population</td><td>".$row['Population']."</td></tr>"; echo "<tr><td colspan=\"2\"><strong>Regulations</strong></td></tr>"; echo "<tr><td colspan=\"2\">"; $string = $row['modifiers']; $var = explode("\n",$string); $value="0"; while(isset($var[$value])) { echo $var[$value].", "; $value++; } echo "</td></tr>"; } /* This is line 102 */ echo"<tr><td colspan=\"2\" align=\"center\"><a href=\"office_cities.php\">Back To All Cities</a></td></tr></table> <table class=\"tablemain\" align=\"center\" border=\"0\"><tr><td><form action='' method='post'>Building:<select name='build'>"; error: Parse error: syntax error, unexpected T_ELSE in C:\xampp\htdocs\Games\Tycoon\office_cities.php on line 102 Link to comment Share on other sites More sharing options...
morrisjohnny Posted December 4, 2007 Author Share Posted December 4, 2007 Sorry about double post it seems to stopped loading so i clicked re-submitt Link to comment Share on other sites More sharing options...
justsomeguy Posted December 4, 2007 Share Posted December 4, 2007 You're probably looking at it in a text editor that is using word wrap. This is the else I'm talking about: echo"</select></td></tr><td><input type='submit' /></form></tr></table>"; }else // this is line 102{/*$_GET['q'] Is not set*/ Link to comment Share on other sites More sharing options...
morrisjohnny Posted December 5, 2007 Author Share Posted December 5, 2007 Yes i am aware that is the problem line but i don't see where i have missed the } from? I was hoping someone would be able to show me?I used Dreamweaver and this it is the only script i have the stupid } problem for i've coded loads of php before but i really can't seem to find the missing }It doesn't matter i've just spent the last few hours recoding it all and now it works so problem solved good job i do back ups every night Link to comment Share on other sites More sharing options...
justsomeguy Posted December 5, 2007 Share Posted December 5, 2007 I thought it was this if statement at the top:if (isset($_GET['q'])){But I didn't notice there was another if statement before that one. Without examining the code, it could be either one. If you go through the code matching braces yourself you'll find which one you missed. Another thing I see now is there are 2 else statements at the end. else{/*$_GET['q'] Is not set*/ echo"</head> <body> <table class=\"tablemain\" align=\"center\" width=\"500\"> <tr><td class=\"header\" colspan=\"3\"><b>Cities Aviable</b></td></tr> <tr><td><strong>Name</strong></td><td><strong>Population</strong></td><td><strong>Region</strong></td></tr>"; $db=mysql_connect($main_hostname, $main_username, $main_password); mysql_select_db($main_databse, $db); $result = mysql_query("SELECT * FROM $main_cities"); while($row = mysql_fetch_array($result)) { echo "<tr><td><a href=\"office_cities.php?q=".$row['ID']."\">".$row['Name']."</td><td>".$row['Population']."</td><td>".$row['Region']."</td></tr>"; } "</table> </body> </html>";}else{include("log_in.php");}?>It doesn't make sense to have that:else{}else{}But if you rewrote it then it's probably fine. Link to comment Share on other sites More sharing options...
morrisjohnny Posted December 6, 2007 Author Share Posted December 6, 2007 thier was to elses at the bottom because their was two statements at the top if ($logged_in) {if (isset($_GET['q'])) but yeah i've recoded it and it's fine, cheers anyway Link to comment Share on other sites More sharing options...
justsomeguy Posted December 6, 2007 Share Posted December 6, 2007 Right, but the way the brackets were set up indicated that one else was right after the other one, not that one if/else ended and then the other ended. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.