0

我想知道为什么我的插入语句不起作用。数据库中没有显示任何记录,也没有显示任何错误。这是代码

<?php 
    if(isset($_POST['submit'])){
        $username = trim($_POST['username']);
        $password = trim($_POST['password']);
        $conf_pass = trim($_POST['conf_password']);
        $email = trim($_POST['email']);
        require_once('./includes/Db/CheckPassword.php');
        $check_pwd = new Db_CheckPassword($password);
        $passwordOK =$check_pwd->check();
        $password_match = Db_CheckPassword::confirmPassword($password,$conf_pass);
        require_once('./includes/Db/CheckUsername.php');
        $check_user = new Db_CheckUsername($username,$conn);
        $userOK = $check_user->check();

        if($userOK && $passwordOK && $password_match){
            $hashedpass = crypt($password);

            $sql = "INSERT INTO accounts ('username','password','email') VALUES('{$username}','{$hashedpass}','{$email}')";
            $conn->query($sql);
        }else{
            $pass_error =  $check_pwd -> getErrors();
            $user_error  = $check_user->getErrors();
        }
    }
?>

这是我将记录插入数据库的地方

if($userOK && $passwordOK && $password_match){
                $hashedpass = crypt($password);

                $sql = "INSERT INTO accounts ('username','password','email') VALUES('{$username}','{$hashedpass}','{$email}')";
                $conn->query($sql);
4

1 回答 1

1

在 mySQL 中,标识符引号字符是反引号,因此将列名周围的单引号替换为反引号:

$sql = "INSERT INTO accounts (`username`,`password`,`email`)    
                     VALUES('{$username}','{$hashedpass}','{$email}')";
于 2012-06-24T05:54:47.803 回答