Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New Coder
    Join Date
    Jul 2011
    Location
    Kansas
    Posts
    15
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Question Parse Error on Closing PHP Line??

    I'm coding a registration form and I'm a newbie. I did all the basic stuff and closed my PHP, but it still says there's a parse error on the line my PHP closes.

    PHP Code:
    <?php
    //This is just starting a session.
    session_start();

    //Database info.
    $dbhost "localhost";
    $dbname "sky";
    $dbuser "sky";
    $dbpass "105000";

    //Either this thing connects, or it's gunna die.
    $con mysql_connect($dbhost$dbuser$dbpass) or die("MySQL Error: " mysql_error());
    mysql_select_db($dbname) or die("MySQL Error: " mysql_error());

    //First, we store the information gathered from the form in variables.
    $username=$_POST['username'];
    $pass=$_POST['password'];
    $email=$_POST['email'];

    $password=md5($pass); //Here, we use the md5() function to encrypt the user's password.
    $confirm_password=$_POST['confirmpass']; //NOW we store the confirmation password.
     

    $queryuser=mysql>("SELECT * FROM people WHERE username='$username'");
    $checkuser=mysql_num_rows($queryuser); //This query will check to see if the inserted username is already taken or not.

    $queryemail=mysql>("SELECT * FROM people WHERE email='$email'");
    $checkemail=mysql_num_rows($queryemail); //This does the same as the first query, but instead checks for the inserted email address.

    if($checkuser != 0)
    { echo 
    "Sorry, ".$username." is already taken."; } //If the username is already taken, it will display a message.
    else {
        if(
    $pass != $confirm_password//Checks to see if the two passwords macth or not.
        
    { echo "Your passwords don't match."; }
    else {
        if(
    $checkemail != 0//if the email is already taken, it will display a message.
        
    { echo "Sorry, ".$email." is already registered.."; }
    else {
        if(
    $username=""//Checks to see if the user actually inserted a username.
        
    { echo "Please provide a username."; } 
    else {
        if(
    $password=""//Checks to see if the user actually inserted a password.
        
    { echo "Please provide a password."; } 
    else {
        if(
    $email=""//Checks to see if the user actually inserted an email address.
        
    { echo "Please provide an email address."; }
    else {
    $insert_user mysql>("INSERT INTO login (id, username, password, email, date, banned, level) VALUES(NULL, '$username', '$password', '$email', NULL, 'No', 'Member')"); }; //Inserts the data if everything checks out okay.
     
    if($insert_user//Did the information successfully insert into the database?
    { echo "You successfully registered!"; } //If yes, then congrats!
    else
    { echo 
    "Gosh dang it, there was an error in registration. ".mysql_error(); }; //If not, then... Well.. That sucks.

    mysql_close($con); //Closes the connection made in the dbconnect.php script.

    ?>
    Any ideas? :confused:

  • #2
    Regular Coder nomanic's Avatar
    Join Date
    Feb 2009
    Location
    United Kingdom
    Posts
    255
    Thanks
    9
    Thanked 33 Times in 33 Posts
    none of your else statements close brackets, so the parser finishes the file incomplete

    Code:
    else {
        if($pass != $confirm_password) //Checks to see if the two passwords macth or not.
        { echo "Your passwords don't match."; }
    should be

    Code:
    else {
        if($pass != $confirm_password) //Checks to see if the two passwords macth or not.
        { echo "Your passwords don't match."; }
    }
    for each of the else statements

  • Users who have thanked nomanic for this post:

    Skylear (07-22-2011)

  • #3
    New Coder
    Join Date
    Jul 2011
    Location
    Kansas
    Posts
    15
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Angry

    Thanks, nomanic. I was stupid not to realize that. :P
    But even after fixing it, my PHP Syntax checker (VERY useful!) built into my IDE said there was another parse error on line 36. >:/

    PHP Code:
    else { <--Line in question.
        if(
    $checkemail != 0//if the email is already taken, it will display a message.
        
    { echo "Sorry, ".$email." is already registered.."; }
        }
    else {
        if(
    $username=""//Checks to see if the user actually inserted a username.
        
    { echo "Please provide a username."; } 
        }
    else {
        if(
    $password=""//Checks to see if the user actually inserted a password.
        
    { echo "Please provide a password."; } 
        }
    else {
        if(
    $email=""//Checks to see if the user actually inserted an email address.
        
    { echo "Please provide an email address."; }
        }
    else {
    $insert_user mysql>("INSERT INTO login (id, username, password, email, date, banned, level) VALUES(NULL, '$username', '$password', '$email', NULL, 'No', 'Member')"); 
          }; 

  • #4
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,479
    Thanks
    63
    Thanked 538 Times in 525 Posts
    @skylear: Click the coding styles link in my signature for some advice on your issue. You will see why when you get there.
    I can't really think of anything to write here now...

  • #5
    New Coder
    Join Date
    Jul 2011
    Location
    Kansas
    Posts
    15
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Thanks, tango, but I would prefer to stick with my current editor. All I need right now is a fix to this cursed parse error. :/

  • #6
    New Coder
    Join Date
    Jul 2011
    Location
    Kediri - Indonesia
    Posts
    61
    Thanks
    2
    Thanked 19 Times in 19 Posts
    i sure, code will do "insert new username" even when posted variable are empty. all check will return true, because you not compare the value. look:
    PHP Code:
    if($username=""
    that's not mean "if $username is empty". so you need to compare values with just replace "=" with "==".
    PHP Code:
    if($username==""
    then, you don't close any open statement. i moded your code to look better, so we easy to trace where is a problem, and i know if any unclosed statement on your code.

    PHP Code:
    <?php
    //This is just starting a session.
    session_start();

    //Database info.
    $dbhost "localhost";
    $dbname "sky";
    $dbuser "sky";
    $dbpass "105000";

    //Either this thing connects, or it's gunna die.
    $con mysql_connect($dbhost$dbuser$dbpass) or die("MySQL Error: " mysql_error());
    mysql_select_db($dbname) or die("MySQL Error: " mysql_error());

    //First, we store the information gathered from the form in variables.
    $username=$_POST['username'];
    $pass=$_POST['password'];
    $email=$_POST['email'];

    $password=md5($pass); //Here, we use the md5() function to encrypt the user's password.
    $confirm_password=$_POST['confirmpass']; //NOW we store the confirmation password.
     

    $queryuser=mysql>("SELECT * FROM people WHERE username='$username'");
    $checkuser=mysql_num_rows($queryuser); //This query will check to see if the inserted username is already taken or not.

    $queryemail=mysql>("SELECT * FROM people WHERE email='$email'");
    $checkemail=mysql_num_rows($queryemail); //This does the same as the first query, but instead checks for the inserted email address.

    if($checkuser != 0){ 
        echo 
    "Sorry, ".$username." is already taken."
    //If the username is already taken, it will display a message.
    else {
        if(
    $pass != $confirm_password){ 
            echo 
    "Your passwords don't match."
        }
    //Checks to see if the two passwords macth or not.
        
    else {
            if(
    $checkemail != 0){ //if the email is already taken, it will display a message.
                
    echo "Sorry, ".$email." is already registered.."
            }
            else {
                if(
    $username==""){ //Checks to see if the user actually inserted a username.
                    
    echo "Please provide a username."
                } 
                else {
                    if(
    $password==""){ //Checks to see if the user actually inserted a password.
                        
    echo "Please provide a password."
                    } 
                    else {
                        if(
    $email==""){ //Checks to see if the user actually inserted an email address.
                            
    echo "Please provide an email address."
                        }
                        else {
    //Inserts the data if everything checks out okay.
                            
    $insert_user mysql>("INSERT INTO login (id, username, password, email, date, banned, level) VALUES(NULL, '$username', '$password', '$email', NULL, 'No', 'Member')"); 
                        }; 
     
                        if(
    $insert_user//Did the information successfully insert into the database?
                        
    { echo "You successfully registered!"; } //If yes, then congrats!
                        
    else
                        { echo 
    "Gosh dang it, there was an error in registration. ".mysql_error(); }; //If not, then... Well.. That sucks.

                        
    mysql_close($con); //Closes the connection made in the dbconnect.php script.

    ######### from here, you not close any statement, so just closed it #############
                    
    }
                }
            }
        }
    }
    ############# eof ##############

    ?>
    hope it helps

  • #7
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,479
    Thanks
    63
    Thanked 538 Times in 525 Posts
    Quote Originally Posted by Skylear View Post
    Thanks, tango, but I would prefer to stick with my current editor. All I need right now is a fix to this cursed parse error. :/
    You will be seeing a lot more parse errors unless you change your STYLE of coding. I didn't suggest you change editors, my post uses Notepad++ but any editor is capable of using those coding styles.

    If you always have your opening and closing braces {} on a seperate line and indented it makes your code far easier to read. Trust me, I used to code like you, it got sloppy and infuriating to fix. It's up to you if you want to listen to someone with experience or not.

    Look at this:
    PHP Code:
    function a()
       {
       function 
    b()
          {
          function 
    c()
             {
             function 
    d()
                {
                
    //See how much easier this is to understand?
                
    }
             }
          }
       } 
    I can't really think of anything to write here now...


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •