简体   繁体   中英

INSERT isn't working

As you can read in the title, I have a problem with my INSERT. I am working on a register page, so here is the code I have :

if ($AllGood) {
        $Data = $DB->prepare("INSERT into `users` (pseudo, email, password, skype, reg_date, rank, picture, reg_ip, last_ip, group) VALUES (':pseudo',              ':email', ':password', ':skype', ':date', ':rank', ':picture', ':reg_ip', ':last_ip', ':group')");

        $Data->bindParam(':pseudo', $pseudo, PDO::PARAM_STR);
        $Data->bindParam(':email', $email, PDO::PARAM_STR);
        $Data->bindParam(':password', $pswd, PDO::PARAM_STR);
        $Data->bindParam(':skype', $shit, PDO::PARAM_STR);
        $Data->bindParam(':date', $date, PDO::PARAM_STR);
        $Data->bindParam(':rank', $rank, PDO::PARAM_STR);
        $Data->bindParam(':picture', $shit, PDO::PARAM_STR);
        $Data->bindParam(':reg_ip', $_SERVER['REMOTE_ADDR'], PDO::PARAM_STR);
        $Data->bindParam(':last_ip', $_SERVER['REMOTE_ADDR'], PDO::PARAM_STR);
        $Data->bindParam(':group', $shit, PDO::PARAM_STR);
        $Data->execute();

        $Data->closeCursor(); // End the connexion
            echo "YOU DONE PHP, GO TAKE A BREAK";
}

The following code is perfectly executing to the last line. But when I go check in my DB I don't have anything :// ( I don't have a problem with the connection at all , everything is fine about it ).

group is a reserved key word so u need to backtick as

`group`

INSERT into `users` 
(
pseudo, email, password, skype, reg_date, rank, picture, reg_ip, last_ip, `group`
)

Check here

http://dev.mysql.com/doc/refman/5.0/en/reserved-words.html

我建议通过设计避免此问题,您可以将列名称更改为(user_group)或使用反引号将其更改为其他名称。

Anythi e you use a MYSQL RESERVED KEYWORD You need to escape it with backticks `, this will let database understand that it is a column

`group`

From documentation

Certain words such as SELECT, DELETE, or BIGINT are reserved and require special treatment for use as identifiers such as table and column names. This may also be true for the names of built-in functions.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM