简体   繁体   中英

Register a generated uniqid in database

Today I need your help. I'm actually coding a register form and for each new registration I generate a key with the uniqid() function.

The problem is when I try to insert my generated key in my database I've this error:

Erreur: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'key) VALUES('','test','test','test@test.com','7c4a8d09ca3762af61e59520943dc26494' at line 1

The field for the key in my database is set to VARCHAR(90) .

I've looked for an answer on Google or here but I haven't found anyone with the same issue .

Does anyone knows where is my problem please ?

Thks, Antho

EDIT:

Here is my SQL Request:

$key = uniqid();

try{
    $sql = "INSERT INTO users(id,name,firstname,mail,pass,status,avatar,key) VALUES('','$name','$firstname','$mail','$pass','$status','$avatar','$key')";
    $req = $db->exec($sql);

    echo 'OK';
}catch(PDOException $e){
    echo 'Erreur: '.$e->getMessage();
}

I believe KEY is a mysql reserved word. Try escaping it with

`key`

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