KyelJmD
KyelJmD

Reputation: 4732

Inserting Data in mysqli is not working

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);

Upvotes: 0

Views: 609

Answers (1)

Dr.Molle
Dr.Molle

Reputation: 117314

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}')";

Upvotes: 1

Related Questions