FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Cannot find parse error





welshsteve
Hi everyone, I'm getting a parse error with the below code. I cannot find it at all. Can anybody help? It thinks the error is in the last line of the whole page, which suggests I've missed a bracket out or something, but my code editor can't find it.

Parse error: syntax error, unexpected $end in /website/s_cup_sw.php on line 217

Here's the php portion of the page.

Code:

<?php
$con = mysql_connect("SERVER","USER","PASS");
if (!$con)
  {
  die('Could not connect: ' . mysql_error() . '<br /><br />Please contact the website administrator');
  }

mysql_select_db("DATABASE", $con);
$round = mysql_real_escape_string(stripslashes($_POST["selectround"]));
//$round = $_POST["selectround"];
//$round = mysql_real_escape_string($round);

//ADDED THIS BIT
if (!empty($round)) {
    //do the query
    //display results
$sql = "SELECT * FROM Cup_SWard WHERE Round = ".$round. ";";
//echo $sql;
$result = mysql_query($sql);

//added
if ($round == 1) {
$date = "14th/15th December 2011";
}
elseif ($round == 2) {
$date = "18th/19th January 2012";
}
elseif ($round == 3) {
$date = "15th/16th February 2012";
}
elseif ($round == 4) {
$date = "22nd March / 5th April";
}
else $date = "Sunday 12th May 2012";

if ($round == 1) {
$theround = "1st Round";
}
elseif ($round == 2) {
$theround = "2nd Round";
}
elseif ($round == 3) {
$theround = "Quarter Finals";
}
elseif ($round == 4) {
$theround = "Semi Finals";
}
else $theround = "Final";
//end added code

if (!$result)
echo mysql_error();

echo "<table class='results'>";
echo "<tr><th colspan='6'>" . $theround . " - " . $date . "</th></tr>";

if ($round == 4) {
while($row = mysql_fetch_array($result))
  {
      echo "<tr><th colspan='6' class='sub'>Match " . $row['MatchNo'] . "</th></tr>";
      echo "<tr><td colspan='6'><strong>1st Leg</strong></td></tr>";
      echo "<tr><td class='fix'>" . $row["HomeTeam"] . " (" . $row["HHCap"] . ")</td><td class='fixv'>" . $row["Home1st"] . "</td><td class='fixv'>-</td><td class='fixv'>" . $row["Away1st"] . "</td><td class='fix'>" . $row["AwayTeam"] . " (" . $row['AHCap'] . ")</td><td class='fixv'><a href='javascript:toggleLayer(\"Round" . $row["Round"] . "-" . $row["MatchNo"] ."\");'><img src='images/info.gif' style='border:0;' alt='Info' /></a></td></tr>";
      echo "<tr><td colspan='6' style='margin:0;padding:0;'><table id='Round" .$row["Round"]. "-" .$row["MatchNo"]. "' style='border-collapse:collapse;display:none;'>";
      echo "<tr><td class='scores'>" . $row["hp1-1"] . "</td><td class='scoresv'>" . $row["hs1-1"] . "</td><td class='scoresv'>-</td><td class='scoresv'>" . $row["as1-1"] . "</td><td class='scores'>" . $row["ap1-1"] . "</td></tr>";
      echo "<tr><td class='scores'>" . $row["hp2-1"] . "</td><td class='scoresv'>" . $row["hs2-1"] . "</td><td class='scoresv'>-</td><td class='scoresv'>" . $row["as2-1"] . "</td><td class='scores'>" . $row["ap2-1"] . "</td></tr>";
      echo "<tr><td class='scores'>" . $row["hp3-1"] . "</td><td class='scoresv'>" . $row["hs3-1"] . "</td><td class='scoresv'>-</td><td class='scoresv'>" . $row["as3-1"] . "</td><td class='scores'>" . $row["ap3-1"] . "</td></tr>";
      echo "<tr><td class='scores'>" . $row["hp4-1"] . "</td><td class='scoresv'>" . $row["hs4-1"] . "</td><td class='scoresv'>-</td><td class='scoresv'>" . $row["as4-1"] . "</td><td class='scores'>" . $row["ap4-1"] . "</td></tr>";
      echo "<tr><td class='scores'>" . $row["hp5-1"] . "</td><td class='scoresv'>" . $row["hs5-1"] . "</td><td class='scoresv'>-</td><td class='scoresv'>" . $row["as5-1"] . "</td><td class='scores'>" . $row["ap5-1"] . "</td></tr>";
      echo "<tr><td class='scores'>" . $row["hp6-1"] . "</td><td class='scoresv'>" . $row["hs6-1"] . "</td><td class='scoresv'>-</td><td class='scoresv'>" . $row["as6-1"] . "</td><td class='scores'>" . $row["ap6-1"] . "</td></tr>";
      echo "<tr><td class='scores'>" . $row["hp7-1"] . "</td><td class='scoresv'>" . $row["hs7-1"] . "</td><td class='scoresv'>-</td><td class='scoresv'>" . $row["as7-1"] . "</td><td class='scores'>" . $row["ap7-1"] . "</td></tr>";
      echo "<tr><td class='extrainfo' colspan='6'>&nbsp;<b>Other Information/30+ Breaks:</b><br />" . $row["Breaks1"] . "<br /></td></tr>";
      echo "<tr><td colspan='6'><strong>2nd Leg</strong></td></tr>";
      echo "<tr><td class='fix'>" . $row["AwayTeam"] . " (" . $row["AHCap"] . ")</td><td class='fixv'>" . $row["Away2nd"] . "</td><td class='fixv'>-</td><td class='fixv'>" . $row["Home2nd"] . "</td><td class='fix'>" . $row["HomeTeam"] . " (" . $row['HHCap'] . ")</td><td class='fixv'>&nbsp;</td></tr>";
      echo "<tr><td class='scores'>" . $row["hp1-2"] . "</td><td class='scoresv'>" . $row["hs1-2"] . "</td><td class='scoresv'>-</td><td class='scoresv'>" . $row["as1-2"] . "</td><td class='scores'>" . $row["ap1-2"] . "</td></tr>";
      echo "<tr><td class='scores'>" . $row["hp2-2"] . "</td><td class='scoresv'>" . $row["hs2-2"] . "</td><td class='scoresv'>-</td><td class='scoresv'>" . $row["as2-2"] . "</td><td class='scores'>" . $row["ap2-2"] . "</td></tr>";
      echo "<tr><td class='scores'>" . $row["hp3-2"] . "</td><td class='scoresv'>" . $row["hs3-2"] . "</td><td class='scoresv'>-</td><td class='scoresv'>" . $row["as3-2"] . "</td><td class='scores'>" . $row["ap3-2"] . "</td></tr>";
      echo "<tr><td class='scores'>" . $row["hp4-2"] . "</td><td class='scoresv'>" . $row["hs4-2"] . "</td><td class='scoresv'>-</td><td class='scoresv'>" . $row["as4-2"] . "</td><td class='scores'>" . $row["ap4-2"] . "</td></tr>";
      echo "<tr><td class='scores'>" . $row["hp5-2"] . "</td><td class='scoresv'>" . $row["hs5-2"] . "</td><td class='scoresv'>-</td><td class='scoresv'>" . $row["as5-2"] . "</td><td class='scores'>" . $row["ap5-2"] . "</td></tr>";
      echo "<tr><td class='scores'>" . $row["hp6-2"] . "</td><td class='scoresv'>" . $row["hs6-2"] . "</td><td class='scoresv'>-</td><td class='scoresv'>" . $row["as6-2"] . "</td><td class='scores'>" . $row["ap6-2"] . "</td></tr>";
      echo "<tr><td class='scores'>" . $row["hp7-2"] . "</td><td class='scoresv'>" . $row["hs7-2"] . "</td><td class='scoresv'>-</td><td class='scoresv'>" . $row["as7-2"] . "</td><td class='scores'>" . $row["ap7-2"] . "</td></tr>";
      echo "<tr><td class='extrainfo' colspan='6'>&nbsp;<b>Other Information/30+ Breaks:</b><br />" . $row["Breaks2"] . "<br /></td></tr></table></td></tr>";
  }
echo "</table>";
}
else {
while($row = mysql_fetch_array($result))
  {
      echo "<tr><td class='fix'>" . $row["HomeTeam"] . " (" . $row["HHCap"] . ")</td><td class='fixv'>" . $row["Home1st"] . "</td><td class='fixv'>-</td><td class='fixv'>" . $row["Away1st"] . "</td><td class='fix'>" . $row["AwayTeam"] . " (" . $row['AHCap'] . ")</td><td class='fixv'><a href='javascript:toggleLayer(\"Round" . $row["Round"] . "-" . $row["MatchNo"] ."\");'><img src='images/info.gif' style='border:0;' alt='Info' /></a></td></tr>";
      echo "<tr><td colspan='6' style='margin:0;padding:0;'><table id='Round" .$row["Round"]. "-" .$row["MatchNo"]. "' style='border-collapse:collapse;display:none;'>";
      echo "<tr><td class='scores'>" . $row["hp1-1"] . "</td><td class='scoresv'>" . $row["hs1-1"] . "</td><td class='scoresv'>-</td><td class='scoresv'>" . $row["as1-1"] . "</td><td class='scores'>" . $row["ap1-1"] . "</td></tr>";
      echo "<tr><td class='scores'>" . $row["hp2-1"] . "</td><td class='scoresv'>" . $row["hs2-1"] . "</td><td class='scoresv'>-</td><td class='scoresv'>" . $row["as2-1"] . "</td><td class='scores'>" . $row["ap2-1"] . "</td></tr>";
      echo "<tr><td class='scores'>" . $row["hp3-1"] . "</td><td class='scoresv'>" . $row["hs3-1"] . "</td><td class='scoresv'>-</td><td class='scoresv'>" . $row["as3-1"] . "</td><td class='scores'>" . $row["ap3-1"] . "</td></tr>";
      echo "<tr><td class='scores'>" . $row["hp4-1"] . "</td><td class='scoresv'>" . $row["hs4-1"] . "</td><td class='scoresv'>-</td><td class='scoresv'>" . $row["as4-1"] . "</td><td class='scores'>" . $row["ap4-1"] . "</td></tr>";
      echo "<tr><td class='scores'>" . $row["hp5-1"] . "</td><td class='scoresv'>" . $row["hs5-1"] . "</td><td class='scoresv'>-</td><td class='scoresv'>" . $row["as5-1"] . "</td><td class='scores'>" . $row["ap5-1"] . "</td></tr>";
      echo "<tr><td class='scores'>" . $row["hp6-1"] . "</td><td class='scoresv'>" . $row["hs6-1"] . "</td><td class='scoresv'>-</td><td class='scoresv'>" . $row["as6-1"] . "</td><td class='scores'>" . $row["ap6-1"] . "</td></tr>";
      echo "<tr><td class='scores'>" . $row["hp7-1"] . "</td><td class='scoresv'>" . $row["hs7-1"] . "</td><td class='scoresv'>-</td><td class='scoresv'>" . $row["as7-1"] . "</td><td class='scores'>" . $row["ap7-1"] . "</td></tr>";
      echo "<tr><td class='extrainfo' colspan='6'>&nbsp;<b>Other Information/30+ Breaks:</b><br />" . $row["Breaks1"] . "<br /></td></tr></table></td></tr>";
  }
echo "</table>";
}

mysql_close($con);
?>

Peterssidan
The problem is that if (!empty($round)) { has no closing bracket. If you had used proper indentations you would have spotted the problem right away.
welshsteve
DOH!!! Knew it would be something silly. Thanks Very Happy
Fire Boar
This is why indentation comes highly recommended. More generally, the "unexpected $end" error means that the interpreter got to the end of the file but was expecting more code. This is almost always an unmatched opening bracket, brace or parenthesis.

A programmer's editor can also be very handy for avoiding this kind of error - even something simple like Notepad++ (which every Windows programmer should have as part of their toolkit by the way), because if the cursor is next to a (, ) {, }, [ or ] symbol, it will highlight both it and the matching symbol elsewhere in the document.
welshsteve
Thanks. I actually use notepad++ but didn't notice where the missing } was. Guess I spent so long looking at it I needed a fresh perspective LOL
jcreus
welshsteve wrote:
Thanks. I actually use notepad++ but didn't notice where the missing } was. Guess I spent so long looking at it I needed a fresh perspective LOL

I find running php -l nameofyourfile.php useful; it points you to the exact character which created the error, and some description (although not as accurate as with Python).
welshsteve
jcreus wrote:
welshsteve wrote:
Thanks. I actually use notepad++ but didn't notice where the missing } was. Guess I spent so long looking at it I needed a fresh perspective LOL

I find running php -l nameofyourfile.php useful; it points you to the exact character which created the error, and some description (although not as accurate as with Python).


Thanks I'll make a note of that for the future.
Related topics
Help with new account
Can't get on to cpanel!!
Impossible parse error!
Trouble figuring out a parse error
Parse error: syntax error, unexpected '{' in /home/frih/publ
php error ?[parse error]
Parse error - need help
Accessing mysql database thru software on local machine
PHP Parse error on form handling - New to PHP
Parse error: syntax error, unexpected T_NEW
[PHP] Parse error
Parse Error in PHP I can't figure out.
Help me find the error in my code... mysql_fetch_array():
getting parse error when validating css
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.