我想知道为什么我的insert语句不起作用。数据库中没有显示记录,也没有显示任何错误。这是代码
<?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);
答案 0 :(得分:1)
在mySQL中,标识符引号字符是反引号,因此用反引号替换列名周围的单引号:
$sql = "INSERT INTO accounts (`username`,`password`,`email`)
VALUES('{$username}','{$hashedpass}','{$email}')";