0

I'm new to PHP and I'm currently trying to write a login system, but I keep getting an error which I think is something really simple. But I just can't figure it out and I've looked on the internet but found nothing.

Some code didn't fit so you will see where it needs to be placed back together it's obvious,

Error is

Parse error: syntax error, unexpected ':' in C:... on line 28

Here is all the code I've got and I'm writing it in Atom.

<?php

//Bug list
//R101=Username uses Invalid characters
//R102=USERNAME IS NOT LONG ENOUGH OR TO SHORT
//R103=USERNAME ALREADY EXISTS IN DATABASE
//R104 Email used is not a proper email
//R105=Password too short or long
include('classes/DB.php');

    if (isset( $_POST['createaccount'])) {
    $username = $_POST['username'];
    $password = $_POST['password'];
    $email = $_POST['email'];

    if (!DB::query('SELECT username FROM users WHERE 
username=:username',array(':username'=>$username))) {
    //CHECK IF USERNAME IS LONG ENOUGH
        if (strl($username) >= 4 && strlen($username <= 32)){
        //CHECK FOR VALID CHARACTERS
                if(preg_match('/[a-zA-Z0-9_]+/', $username)){


                        if (filter_var($email,FILTER_VALIDATE_EMAIL)){

                            if (strlen($password) >= 6 && strlen($password) <= 60){
                                //USERNAME IS VALID AND WILL NOW BE CREATED
                                    DB::query('INSERT INTO users VALUES (\'\ 
',:username, :password, :email)', array(':username'=>$username, 
':password'=>password_hash($password, PASSWORD_BCRYPT), ':email'=> $email));
                                    echo 'Success';
                            } else {
                                "Password Invalid (R105)"
                            }
                        } else {
                          echo "Username Invalid (R104)"
                        }
                    } else {
              echo "Username Invalid (R101) "
                    }
            } else {
                echo "Username Invalid (R102)"

            }

    } else {
        echo 'Username Is Taken (R103)';

    }
}
?>

<h1>Register</h1>
<form action="create-account.php" method="post">
    <input type="text" name="username" value="" placeholder="Username"><p />
    <input type="password" name="password" value="" placeholder="Password"><p />
    <input type="email" name="email" value="" placeholder="name@email.com"><p />
    <input type="submit" name="createaccount" value="Create Account">

</form>
Striezel
  • 3,693
  • 7
  • 23
  • 37
  • Why your echos doesnt have ";" ? Why did you escape strings like with '(\'\ ' ? – Ulises Jun 01 '18 at 16:32
  • error lies in this line DB::query('INSERT INTO users VALUES (\'\ ',:username, :password, :email)', array(':username'=>$username, ':password'=>password_hash($password, PASSWORD_BCRYPT), ':email'=> $email)); rectify this – prasanna puttaswamy Jun 01 '18 at 16:34

1 Answers1

0

The following part is causing the error:

 DB::query('INSERT INTO users VALUES (\'\ 
',:username, :password, :email)', array(':username'=>$username, 
':password'=>password_hash($password, PASSWORD_BCRYPT), ':email'=> $email));
                                    echo 'Success';

You are concatenating strings and variables to each other with single quotes. If you do this, you need to place full stops (.) between them. Observing the above snippet you can also see that your code below this part all has the same color. This is because you have an open single quote.

Tom
  • 324
  • 4
  • 11