Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 08-25-2009, 08:52 PM   PM User | #1
firetag
New Coder

 
Join Date: Jul 2009
Posts: 52
Thanks: 6
Thanked 1 Time in 1 Post
firetag is an unknown quantity at this point
error in start and end tags

I am getting this error
Quote:
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();
        
?>
firetag is offline   Reply With Quote
Old 08-25-2009, 09:55 PM   PM User | #2
spidershrief
New to the CF scene

 
Join Date: Aug 2009
Posts: 9
Thanks: 0
Thanked 4 Times in 3 Posts
spidershrief is an unknown quantity at this point
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
spidershrief is offline   Reply With Quote
The Following 2 Users Say Thank You to spidershrief For This Useful Post:
firetag (08-25-2009), whizard (08-25-2009)
Old 08-25-2009, 10:34 PM   PM User | #3
firetag
New Coder

 
Join Date: Jul 2009
Posts: 52
Thanks: 6
Thanked 1 Time in 1 Post
firetag is an unknown quantity at this point
Thanks that worked but now I have more errors :[

Here they are:

Quote:
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.
Quote:
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?
Quote:
Fatal error: Call to undefined function sha2() in C:\wamp\www\test\register.php on line 49
firetag is offline   Reply With Quote
Old 08-25-2009, 10:42 PM   PM User | #4
whizard
Senior Coder

 
whizard's Avatar
 
Join Date: Jan 2005
Location: Philadelphia, PA, USA
Posts: 1,457
Thanks: 10
Thanked 37 Times in 37 Posts
whizard will become famous soon enoughwhizard will become famous soon enough
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
__________________
If you want to use short tags (<? or <?=$var) then make sure short_open_tag is set to "1". It really helps.
Step 1: Learn. Step 2: Search. Step 3: Post here.
whizard is offline   Reply With Quote
Users who have thanked whizard for this post:
firetag (08-25-2009)
Old 08-25-2009, 10:49 PM   PM User | #5
tomws
Senior Coder

 
tomws's Avatar
 
Join Date: Nov 2007
Location: Arkansas
Posts: 2,644
Thanks: 29
Thanked 330 Times in 326 Posts
tomws will become famous soon enoughtomws will become famous soon enough
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?
tomws is offline   Reply With Quote
Old 08-25-2009, 10:56 PM   PM User | #6
firetag
New Coder

 
Join Date: Jul 2009
Posts: 52
Thanks: 6
Thanked 1 Time in 1 Post
firetag is an unknown quantity at this point
Edit: Never mind I just fixed it but I still don't know why I can't use sha256();

Last edited by firetag; 08-25-2009 at 11:56 PM..
firetag is offline   Reply With Quote
Old 08-26-2009, 03:10 AM   PM User | #7
tomws
Senior Coder

 
tomws's Avatar
 
Join Date: Nov 2007
Location: Arkansas
Posts: 2,644
Thanks: 29
Thanked 330 Times in 326 Posts
tomws will become famous soon enoughtomws will become famous soon enough
Because it doesn't exist: http://php.net/manual-lookup.php?pattern=sha256&lang=en
__________________
Are you a Help Vampire?
tomws is offline   Reply With Quote
Old 09-05-2009, 11:21 AM   PM User | #8
searcyemily
New to the CF scene

 
Join Date: Sep 2009
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
searcyemily is an unknown quantity at this point
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!...
searcyemily is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 05:45 PM.


Advertisement
Log in to turn off these ads.