new error..please help...urgently need

A

Anonymous

Guest
if(mysql_num_rows($result)>0

You don't seem to have a closing bracket on this if!
 
Code:
here is my code.....the one in bold is having error!!!!

if(empty($email) || !eregi("^[A-Za-a0-9\_]+@[A-Za-z0-9\_-]+[A-Za-z0-9\_-]+.*",$email))
{
$errmsg .="<li>$email doesn't looks like a valid email address\n";
}
else
{
//if the format is OK, check to see if this user has already
//signed the guesrtbook.Multiple entries are not allowed.
$query = "select * from guestbook where email = '$email'";
$result = safe_query($query);
if(mysql_num_rows($result)>0
{
$errmsg = "<li>$email has already signed this guestbook.\n";
}
}//perform a very simple check on the format of the url supplied
//by he user (if any)
if (!empty($url) && !eregi("^http://[A-Za-z0-9\%\?\_\:\~\/\.-]+$",$url))
{


You are missing a ")" in this line:
if(mysql_num_rows($result)>0

should be:
if(mysql_num_rows($result)>0)
 
if(mysql_num_rows($result)>0
{
$errmsg = "<li>$email has already signed this guestbook.\n";
}

Parse errors almost always occur on a line before they are detected. Since your error said "Unexpected {", it means that the interpreter was expecting something INSTEAD of {, so you can tell that your error is probably just before the {. In this case, it's because you forgot the closing ) for your if statement:
Code:
<?php
if(mysql_num_rows($result)>0)
{ 
   $errmsg = "<li>$email has already signed this guestbook.\n"; 
} 
?>

(Hmm, apparently
PHP:
 tags are screwed up on the board right now. Check out my sig. Ack.)
 
It's one of these again isn't it swirlee? Another parsing error... it seemed that the last post that you answered about parsing was about 5-6 days ago?
PEOPLE CHECK YOUR SYNTHAX, ESPECIALLY CLOSING BRACKETS AND SEMICOLONS!!!!
Hey guys you know that there are editors out there wthat will highlight the brackets, so you can see where it's opened and where its closed? Examples? Well PHP Expert Editor does that, PHP Coder, Ultra Edit and even Dream Weaver will all do that for you. You can really use that when debugging, especially when you are debugging a big project.
My suggestion to you MAC38 is first look at your error, realize where (line) the error is again mostly it is in the line before the one indicated, and then go over the line in detail, not forgetting closing brackets and semicolons if they are needed, if that doesnt help, refer to the previous line and scan that one, and if event that doesnt help then its probably in the line indicated... If the error is nowhere to be found post the code and we might read through it to try to find it for you. but try what i told you to do before first, its almost like proofreading, only in code, it teaches you to pay much more careful attention to your code when you write it.
 
A good habit to get into is closing your brackets and parentheses as soon as you open, then filling in the space in between. This way you'll never forget to close them after you've written a block of code. This is how my workflow tends to look:

Code:
if() { }

// then fill in the if condition and start to fill in the block

if($conditionvar == 1) {
  echo "something";

  while() { }
}

// then fill in the while() condition and start to fill in its block

if($conditionvar == 1) {
  echo "something";

  while(afunction()) { }
}

// then finish the function parameters and the while block

if($conditionvar == 1) {
  echo "something";

  while(afunction($a) && $b) {
      echo "there be dragons here..";
  }
}

See, I never opened a bracket or parentheses pair without immediately closing it. With this method I rarely encounter parse errors, but as gesf suggests, having a bracket-matching editor is very, very helpful. Right now I'm testing out Maguma Workbench, which has some nice features along these lines.
 
Back
Top