Php-试图修复意外情况':'在引用时

时间:2018-06-01 16:24:15

标签: php debugging login

我是PHP的新手,我目前正在尝试编写登录系统,但我一直收到一个错误,我认为这个错误非常简单。但我无法弄清楚,我已经在互联网上看了一眼,却一无所获。

有些代码不合适,所以你会看到它需要放在一起的地方很明显,

错误是

  

解析错误:语法错误,意外':'在C:......第28行

以下是我已经获得的所有代码,并且我是在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>

1 个答案:

答案 0 :(得分:0)

以下部分导致错误:

table(addNA(starwars$Anakin), starwars$Startrek)

您使用单引号将字符串和变量相互连接起来。如果这样做,则需要在它们之间放置句点(。)。观察上面的代码片段,您还可以看到此部分下方的代码都具有相同的颜色。这是因为你有一个开放的单引号。