Inserting Data in mysqli is not working

 ̄綄美尐妖づ 提交于 2020-01-25 23:45:29

问题


I am wondering why my insert statement does not work. There are no records shown in the database and it does not show any errors. Here is the code

<?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();
        }
    }
?>

This is where I insert records into the database

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

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

回答1:


In mySQL the identifier quote character is the backtick , so replace the single-quotes surrounding the column-names by backticks:

$sql = "INSERT INTO accounts (`username`,`password`,`email`)    
                     VALUES('{$username}','{$hashedpass}','{$email}')";


来源:https://stackoverflow.com/questions/11175061/inserting-data-in-mysqli-is-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!