-2

I was making all the checks for the my sign up form and while checking if the length of the field is not bigger than a number, it gave me an error. Not to sure whats 'unexpected' here.

The problem is probably staring at me in the face, but I can't figure it out right now.

This is the error I received:

Parse error: syntax error, unexpected '!' in C:\users\user\xampp\htdocs\CompanyProject\Signup.php on line 15

This is the PHP code I used for to accomplish what I wanted to do:

   if($password == $confirmpass){
            if(!empty($password) AND !empty($username) AND !empty($email)){
                if (strlen($username) >=3 && strlen(trim($username)) !== 0 && strlen($password) >=3 && strlen(trim($password)) !== 0 && strlen($email) >=3 && strlen(trim($email)) !== 0) {
                    if(strlen($username) !<13){
                        if(strlen($password) !<17){
                            $sql ="INSERT INTO users(user,pass,email) VALUES('".$username."','".md5($password)."','".$email."')";
                            mysql_query($sql);
                            header('Location: Login.php');
                        }else{

                            echo "Your password must be between 3 and 17 characters"
                        }

                    }else{
                        echo "Your username must be between 3 and 13 characters."
                    }

                }else{
                    echo "Each field needs atleast 3 characters.";
                }

            }else{
                echo "Please fill out the form.";
            }

        }else{
            echo ("Your passwords do not match");
        }
    }

The error is occuring in these lines:

if(strlen($username) !<13){
                    if(strlen($password) !<17){

Thanks in advance.

Gordynson
  • 67
  • 1
  • 8

2 Answers2

3

The lines below:

 if(strlen($username) !<13){
     if(strlen($password) !<17){

are not valid. They should use >=. e.g.

 if(strlen($username) >= 13){
     if(strlen($password) >= 17){

even then, I'm pretty sure you wanted to write

 if(strlen($username) <= 13){
     if(strlen($password) <= 17){

as your error messages state the rules for your username and password!

I'm not sure I've seen any C derivative language use !< and !>

ADDENDUM: You're also missing upper bound checks on email length (there is one on the wikipedia page here).

You should consider writing a validator function, decomposing those nasty nested ifs which is really difficult code to maintain.

As a starter for 10:

   if($password != $confirmpass){
        echo ("Your passwords do not match");
    return false;
   }

   // what about weird characters?
   if (empty($username) || strlen($username) < 3 || strlen($username) > 13) {
        echo "Your username must be between 3 and 13 characters.";
    return false;
   }


   // what about weird characters?
   if (empty($password) || strlen($password) < 3 || strlen($password) > 17) {
        echo "Your password must be between 3 and 17 characters.";
    return false;
   }


   // you'll want some kind of regex to validate that the email is well formed
   if (empty($email) || strlen($email) < 3 || strlen($email) > 254) {
        echo "Your email must be between 3 and 254 characters.";
    return false;
   }

   $sql ="INSERT INTO users(user,pass,email) VALUES('".$username."','".md5($password)."','".$email."')";
   mysql_query($sql);
   header('Location: Login.php');
Jeff Watkins
  • 6,243
  • 13
  • 17
0

Your syntax is incorrect, you are trying to negate an comparison operator but this is not syntax in PHP. The only valid forms of > and < are:

>= or <=

q.Then
  • 2,691
  • 1
  • 16
  • 29