...

View Full Version : error in start and end tags



firetag
08-25-2009, 09:52 PM
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
?>
Can anyone tell me why this error is occurring?
And/Or give me any other kind of advice on the script?

<?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();
?>

spidershrief
08-25-2009, 10:55 PM
hey the error is just in the closing bracket of the Funtion:
it should be this:



<?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:


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

firetag
08-25-2009, 11:34 PM
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:

$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

whizard
08-25-2009, 11:42 PM
The first error (undefined offset) means that you are trying to reference an array element that doesnt exist ($sInput[5]).

Try



$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.
could you mean sha1() (http://us2.php.net/manual/en/function.sha1.php) instead? (There's no sha2() as far as I know)
Dan

tomws
08-25-2009, 11:49 PM
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.

firetag
08-25-2009, 11:56 PM
Edit: Never mind I just fixed it but I still don't know why I can't use sha256();

tomws
08-26-2009, 04:10 AM
Because it doesn't exist: http://php.net/manual-lookup.php?pattern=sha256&lang=en

searcyemily
09-05-2009, 12:21 PM
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 (http://www.actual-exams.com/642-061-practice-exam.htm) 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 (http://www.actual-exams.com/RH202-practice-exam.htm) which I had passed last two months back. Also I am trying to complete my pending thesis of 000-973 exam (http://www.actual-exams.com/000-973-practice-exam.htm) 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!...



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum