Your database must enforce uniqueness. When you try to execute a SELECT query to find if data doesn’t exist, a race condition exists where multiple concurrent instances of your script will all find that the value doesn’t exist and attempt to insert it.
The simple solution to prevent duplicates is to define the column(s) that must be unique (userId and useremail) as unique indexes, then just attempt to insert the data and detect if a duplicate index error occurs.
The reason your existing code doesn’t work is because you must supply an array to the ->execute() call. This is either treating the string as an array of characters and is using the first character as the value or it is producing php errors. Do you have php’s error reporting set to E_ALL and display_errors set to ON, preferably in the php.ini on your system, and have you set the PDO error mode to use exceptions for errors?
I tought they where set to on, since everytime i have errors I get them on a log file then I check them and solve them, but this particuraly dosen’t show up in a log.
Ok so I’ve checked E_ALL and they are set to [Off], i’ll turn them [ON]. And pdo mode to exceptions set to: PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
Ok so now I’ll be able to see this errors right?
Thank you guys for your answers.
I get the id and username from a json api when the user enters this interface I’ve made, and I’m making like a silly panel where you can check your personal info, and I’m tryng to store this data so I can add the posibility of making a bigger database table where you can choose like having the website in other colors, having some options disabled if you don’t wan’t them, reordering your main panel so you can see your stuff like you would like it, etc.
I just explained to enter in context xD