I need a mechanism that inserts the data from a newly registered user to a database. I use PDO to do this, and this is my current code:
$dbc = new PDO('mysql:host=localhost;dbname=*****', *****, *****);
$insert_query = $dbc->prepare('INSERT INTO members(name, gender, email, pass)
VALUES(:name, :gender, :email, :pass) WHERE email = :email LIMIT 1');
$insert_query->execute(array(':name' => $name, ':gender' =>
$gender, ':email' => $email, ':pass' => $pass));
However, nothing happens when a user submits the register form. I tried to echo $gender, $name, $email and $pass, and they all showed correct values. I am new to PDO, and I’m not sure what the problem could be at all. Is it a syntax error of some sort, or is it something else?
I don’t receive any error messages.
I don’t believe it is valid to include a
LIMITclause in anINSERTstatement.LIMITis not among the optional clauses in the MySQLINSERTsyntax reference.You also have a
WHEREclause, which is also invalid in anINSERTstatement.I suspect you don’t have error reporting turned on, since this ought to have been a fatal error or thrown an exception if the statement failed to
prepare()due to syntax errors. You would have gotten an error similar toBy definition, an
INSERTstatement inserts exactly as many rows as you have()groups* for in yourVALUES (), so there’s no need for aLIMITanyway. You could use aLIMITin anINSERT INTO...SELECT...statement, but in that case, theLIMITis a clause of theSELECTcomponent rather than theINSERT.* Ignoring potential key violations or other insert problems, obviously
The fact that you have conflated multiple components (
WHERE,LIMIT) fromUPDATEstatements makes me wonder if you actually intended this to be anUPDATErather than anINSERTstatement to begin with.INSERTis only for new rows.UPDATEis for changing existing rows, and bothWHEREandLIMITare valid inUPDATE.That would look like: