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 8 of 8
  1. #1
    New Coder
    Join Date
    Jul 2009
    Posts
    52
    Thanks
    6
    Thanked 1 Time in 1 Post

    error in start and end tags

    I am getting this error
    Parse error: parse error in C:\wamp\www\test\register.php on line 54
    which is on this line of code
    PHP Code:
    ?> 
    Can anyone tell me why this error is occurring?
    And/Or give me any other kind of advice on the script?
    PHP Code:
      <?php
      ob_start
    ();
          include(
    "conn.php");
    function 
    register($name $email $password $password2){
            
    //validate input
                
    $sql="SELECT * FROM log_in WHERE email='" $email "'";//returns true if username already exists
                    //stripslashes and mysql_real_escape-string
                        
    $sInput= array(1=>$name ,$email ,$password ,$password2);
                        
    $x=1;
                        do{
                            
    $sInput[$x]=stripslashes($sInput[$x]);
                            
    $sInput[$x]=mysql_real_escape_string($sInput[$x]);
                            
    $x++;
                        }while(
    $x<= 5);
                    
    //END stripslashes and mysql_real_escape_string
                
                
    if((!$name) || (!$email) || (!$password) || (!$password2)){//if user didnt enter some field
                    
    $errors[]= "Please fill in all required fields.<br />";
                }
                if(
    $password != $password2){//if password dont match
                    
    $errors[]= "The passwords must match.<br />";
                }
                if(
    $sql){//if username exists
                    
    $errors[]= "That username already exists.<br />";
                }
                if(
    checkEmail($email)){}
                    else{ 
    $errors[]="Email must be in the format of aa&amp;aa.aaa .<br />";
                if(
    strlen($password)<=5){//if passoword isnt atleast 5 characters
                    
    $errors[]= "Username must be atleast 5 characters long.<br />";    
                }
                    else if(
    strlen($password)>=33){//if password exceeds 32 characters
                        
    $errors[]= "Username cannot exceed 32 characters.<br />";
                    }
                
                if(
    false){//if errors exist return errors
                    
    return false;
                }
                
            
    //END input validation
            
    $password=sha2($password);
            
    mysql_query("INSERT INTO log_in(name,email,password) VALUES ('".$name."' , '".$email."' , '".$password."')") or die(mysql_error());
            return 
    true;

        }
    //END FUNCTION REGISTER
        
    $_POST["email"]=$email;
        
    $_POST["password"]=$password;
        
    $_POST["passagain"]=$pass2;
        
    $_POST["name"]=$name;
                
    $bools=register($name,$email,$password,$pass2);
                if(
    $bools==true)
                    {echo 
    'Congrats youre registration was succesful.';} 
                else{echo 
    'Something went wrong.';}
            
    ob_end_flush();
            
    ?>

  • #2
    New to the CF scene
    Join Date
    Aug 2009
    Posts
    9
    Thanks
    0
    Thanked 4 Times in 3 Posts
    hey the error is just in the closing bracket of the Funtion:
    it should be this:

    PHP Code:
      <?php
      ob_start
    ();
          include(
    "conn.php");
    function 
    register($name $email $password $password2){
            
    //validate input
                
    $sql="SELECT * FROM log_in WHERE email='" $email "'";//returns true if username already exists
                    //stripslashes and mysql_real_escape-string
                        
    $sInput= array(1=>$name ,$email ,$password ,$password2);
                        
    $x=1;
                        do{
                            
    $sInput[$x]=stripslashes($sInput[$x]);
                            
    $sInput[$x]=mysql_real_escape_string($sInput[$x]);
                            
    $x++;
                        }while(
    $x<= 5);
                    
    //END stripslashes and mysql_real_escape_string
                
                
    if((!$name) || (!$email) || (!$password) || (!$password2)){//if user didnt enter some field
                    
    $errors[]= "Please fill in all required fields.<br />";
                }
                if(
    $password != $password2){//if password dont match
                    
    $errors[]= "The passwords must match.<br />";
                }
                if(
    $sql){//if username exists
                    
    $errors[]= "That username already exists.<br />";
                }
                if(
    checkEmail($email)){}
                    else{ 
    $errors[]="Email must be in the format of aa&amp;aa.aaa .<br />";}
                if(
    strlen($password)<=5){//if passoword isnt atleast 5 characters
                    
    $errors[]= "Username must be atleast 5 characters long.<br />";    
                }
                    else if(
    strlen($password)>=33){//if password exceeds 32 characters
                        
    $errors[]= "Username cannot exceed 32 characters.<br />";
                    }
                
                if(
    false){//if errors exist return errors
                    
    return false;
                }
                
            
    //END input validation
            
    $password=sha2($password);
            
    mysql_query("INSERT INTO log_in(name,email,password) VALUES ('".$name."' , '".$email."' , '".$password."')") or die(mysql_error());
            return 
    true;

        }
    //END FUNCTION REGISTER
        
    $_POST["email"]=$email;
        
    $_POST["password"]=$password;
        
    $_POST["passagain"]=$pass2;
        
    $_POST["name"]=$name;
                
    $bools=register($name,$email,$password,$pass2);
                if(
    $bools==true)
                    {echo 
    'Congrats youre registration was succesful.';} 
                else{echo 
    'Something went wrong.';}
            
    ob_end_flush();
            
    ?>
    at the line:
    PHP Code:
                if(checkEmail($email)){}
                    else{ 
    $errors[]="Email must be in the format of aa&amp;aa.aaa .<br />"
    i think u forgot to close the else brackets

  • The Following 2 Users Say Thank You to spidershrief For This Useful Post:

    firetag (08-25-2009), whizard (08-25-2009)

  • #3
    New Coder
    Join Date
    Jul 2009
    Posts
    52
    Thanks
    6
    Thanked 1 Time in 1 Post
    Thanks that worked but now I have more errors :[

    Here they are:

    Notice: Undefined offset: 5 in C:\wamp\www\test\register.php on line 20

    Deprecated: Function eregi() is deprecated in C:\wamp\www\test\register.php on line 5

    Fatal error: Call to undefined function sha2() in C:\wamp\www\test\register.php on line 49
    I just have a few questions now:

    1.
    On line 20 which includes this set of code:
    PHP Code:
     $sInput= array(1=>$name ,$email ,$password ,$password2);
                        
    $x=1;
                        do{
                            
    $sInput[$x]=stripslashes($sInput[$x]);
                            
    $sInput[$x]=mysql_real_escape_string($sInput[$x]);
                            
    $x++;
                        }while(
    $x<= 5); 
    Is there a way of doing stripslashes and mysql_real_escape_string in those few lines of code like I was trying to do?

    2.
    No idea what deprecated means and a google search didn't suffice.
    Deprecated: Function eregi() is deprecated in C:\wamp\www\test\register.php on line 5
    Does eregi() need to be included or something?

    3.
    Why am I getting this error, I thought sha2() was a built in function?
    Fatal error: Call to undefined function sha2() in C:\wamp\www\test\register.php on line 49

  • #4
    Senior Coder whizard's Avatar
    Join Date
    Jan 2005
    Location
    Philadelphia, PA, USA
    Posts
    1,662
    Thanks
    14
    Thanked 76 Times in 76 Posts
    The first error (undefined offset) means that you are trying to reference an array element that doesnt exist ($sInput[5]).

    Try

    PHP Code:
     $sInput= array(1=>$name ,$email ,$password ,$password2);
                        
    $x=1;
                        do{
                            
    $sInput[$x]=stripslashes($sInput[$x]);
                            
    $sInput[$x]=mysql_real_escape_string($sInput[$x]);
                            
    $x++;
                        }while(
    $x<= count($sInput)); 
    That way it will never loop more than the length of the array.

    2. Deprecated means no longer considered part of the language, but still works on old versions. It won't work as of PHP 6, I believe.

    3. Not sure about this one right off the top of the head.
    Edit: could you mean sha1() instead? (There's no sha2() as far as I know)

    Dan
    PHP Tip: If you want to use short tags (<? or <?=$var) then make sure short_open_tag is set to "1". It really helps.

    Don't forget to save everyone time and mark your thread as Resolved :)

    "Also note that it is your responsibility to die() if necessary."

    DON'T USE THE MYSQL_ EXTENSION

  • Users who have thanked whizard for this post:

    firetag (08-25-2009)

  • #5
    Senior Coder tomws's Avatar
    Join Date
    Nov 2007
    Location
    Arkansas
    Posts
    2,644
    Thanks
    29
    Thanked 330 Times in 326 Posts
    Quote Originally Posted by whizard View Post
    2. Deprecated means no longer considered part of the language, but still works on old versions. It won't work as of PHP 6, I believe.
    Just an additional note, the ereg functions are deprecated as of 5.3.0 which was released 2009-06-30. And whizard is correct about them going away in PHP6: http://php.net/ereg.
    Are you a Help Vampire?

  • #6
    New Coder
    Join Date
    Jul 2009
    Posts
    52
    Thanks
    6
    Thanked 1 Time in 1 Post
    Edit: Never mind I just fixed it but I still don't know why I can't use sha256();
    Last edited by firetag; 08-26-2009 at 12:56 AM.

  • #7
    Senior Coder tomws's Avatar
    Join Date
    Nov 2007
    Location
    Arkansas
    Posts
    2,644
    Thanks
    29
    Thanked 330 Times in 326 Posts
    Are you a Help Vampire?

  • #8
    New to the CF scene
    Join Date
    Sep 2009
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I'm so happy to being a part of this large community of successful and future of great geeks found here!! I hope joining in this site would really help me and getting the best knowledge gigantically! Infect now a days i'm preparing for 642-061 exam for achieving the certification. Although it is not hard to get certified but it keeps me busy. I've also attained certification of another course of RH202 exam which I had passed last two months back. Also I am trying to complete my pending thesis of 000-973 exam project which i hope will be completed soon. I really enjoyed my stay over here and have knowledge while stopping by. And hope to hear from you folks!...


  •  

    Posting Permissions

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