Page 1 of 1

Yet another error debug thread...

Posted: Fri Mar 12, 2010 3:12 am
by 120816
Hello all, let me just say I'm very impressed with the setup here and I find it great that you guys are taking time out to help out beginners like me interested in PHP. We all gotta start somewhere and I'm thankful for the helpful videos and tutorials available on a site like this.

Anyways, I'm extremely confused to why I'm getting this error. This is essentially taken from the source code in the MMO tutorial videos; hallsofvalhalla's register code. I just changed the variables name, database names and a few other to learn about how it works on PHP. Can someone explain to me why I get...

Parse error: parse error in C:\wamp\www\GuyOnline\RegisterUser.php on line 57...

Code: Select all

<?php
include 'RegisterConnect.php';
?>

<?php
$username=$_POST['username'];
$password=$_POST['password'];
$confirm=$_POST['confirm'];
$email=$_POST['email'];
$username=strip_tags($username);
$email=strip_tags($email);

if ($email == "")
{
echo "You didn't enter an email address!<br>";
echo " <br><A href='RegisterPage.php'>Go back.</a><br>";
    exit;
    }
if ($password==$confirm)
{

  $isplayer="SELECT * from playerinfotable where PlayerName='$username'";
  $isplayer2=mysql_query($isplayer) or die("Could not query players table.");
  $isplayer3=mysql_fetch_array($isplayer2);
  if(!$_POST['password'] || !$_POST['confirm'])
  {
     print "You did not enter a password.";
    echo " <br><A href='RegisterPage.php'>Go back.</a><br>";
    exit;
  }
  else if($isplayer3 || strlen($username)>15 || strlen($username)<1)
  {
     print "There is already a player of that name or the name you specified is over 16 letters or less than 1 letter.<br>";
     echo " <br><A href='RegisterPage.php'>Go back.</a><br>";
    exit;
  }
  else
  {
    $isaddress="SELECT * from playerinfotable where PlayerEmail='$email'";
    $isaddress2=mysql_query($isaddress) or die("Could not query for password.");
    $isaddress3=mysql_fetch_array($isaddress2);
    if($isaddress3)
    {
      print "There is already a player with that e-mail address.<br>";
      echo " <br><A href='RegisterPage.php'>Go back.</a><br>";
    exit;
    }
    else
    {
        $password=md5($password);

$SQL = "INSERT into playerinfotable(PlayerName, PlayerPassword, PlayerEmail) VALUES ('$username','$password','$email')";
      mysql_query($SQL) or die("Could not register.");

      print "Thank you for registering."; 
    }
  }                      //Line 57                                                                  =
}

else
{
  print "Your password didn't match or you did not enter a password.<br>";
   echo " <A href='register.php'>Go back</a>";
    exit;
}
echo "<br><br><A href='login.php'>Login Page</a>";
?>
When Line 57 is basically...

Code: Select all

$SQL = "INSERT into playerinfotable(PlayerName, PlayerPassword, PlayerEmail) VALUES ('$username','$password','$email')";
      mysql_query($SQL) or die("Could not register.");     

 print "Thank you for registering.";
    }    
  }      //Line 57                                                                                      =
}
Could someone point me in the right direction? I'm eager to learn.

Re: Yet another error debug thread...

Posted: Fri Mar 12, 2010 4:28 am
by ZeroComp
I think you have an extra brace, I'm just taking a stab at it if I'm wrong oh well

Re: Yet another error debug thread...

Posted: Fri Mar 12, 2010 4:42 am
by Jackolantern
I am not immediately seeing anything jumping out at me. I copied your code into Codelobster for syntax highlighting, and it is usually pretty good about pointing out misspelled keywords, or mismatched braces.

What was that equal sign over to the right on line 57? Now that you commented line 57, it will not be a problem, but if that was there before you commented it, that could have been causing the issue. Remove that equal sign and the comment and see how it works.

Re: Yet another error debug thread...

Posted: Fri Mar 12, 2010 8:18 am
by 120816
Oh God, I feel so stupid.

Thank you Jackolantern and ZeroComp. Some of us aren't naturally gifted at coding as you can see.

Re: Yet another error debug thread...

Posted: Fri Mar 12, 2010 8:41 am
by MAruz
A good practice to avoid the bulk of these kinds of errors is to be strict on your indenting of code.

Every time you open up a "{", make sure the next line is indented with a tab (maybe 4 or 8 spaces if you prefer).
This way it's easier to see where a curly bracket belongs.

Halls doesn't do that in his tutorials, which can make it a bit hard to see where one block should start/end.

Also, software that highlights your syntax helps. Whit this kind of software, you can just click an opening curly bracket, and it will highlight the closing bracket that belongs to it.

Re: Yet another error debug thread...

Posted: Fri Mar 12, 2010 2:24 pm
by hallsofvallhalla
when I am doing large code with lots of braces i comment each brace

example

{////////////start of fight code

blah
blah

}///////////////end of fight code

Re: Yet another error debug thread...

Posted: Sat Mar 13, 2010 4:33 am
by jpoisson
Halls method is probably the most effective.

I do that too sometimes, but I always open an close right away.