FrenchMajesty
FrenchMajesty

Reputation: 1139

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

Upvotes: 2

Views: 79

Answers (3)

Jason OOO
Jason OOO

Reputation: 3552

I suggest to avoid this issue by design, you can change column name like (user_group) or to another name instead using backticks.

Upvotes: 1

Fabio
Fabio

Reputation: 23490

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.

Upvotes: 0

Abhik Chakraborty
Abhik Chakraborty

Reputation: 44844

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

Upvotes: 2

Related Questions