Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You don't specify the id (or key column) in your ON DUPLICATE KEY UPDATE clause.</p> <p>From: <a href="http://dev.mysql.com/doc/refman/5.0/en/insert-on-duplicate.html" rel="nofollow">http://dev.mysql.com/doc/refman/5.0/en/insert-on-duplicate.html</a></p> <blockquote> <p>For example, if column a is declared as UNIQUE and contains the value 1, the following two statements have identical effect:</p> <blockquote> <p>INSERT INTO table (a,b,c) VALUES (1,2,3) ON DUPLICATE KEY UPDATE c=c+1;</p> <p>UPDATE table SET c=c+1 WHERE a=1;</p> </blockquote> </blockquote> <p>What you currently have is most likely changing the last row you inserted into the database and not the duplicate key row. Read the docs on LAST_INSERT_ID(): <a href="http://dev.mysql.com/doc/refman/5.0/en/information-functions.html#function_last-insert-id" rel="nofollow">http://dev.mysql.com/doc/refman/5.0/en/information-functions.html#function_last-insert-id</a></p> <p>Looking back at your question, I know I'm not really/fully answering your question. I'm partially trying to understand what the use case is. In cases where I'm creating a user through code, if it is the admin creating a user, I just set the account active (and set the activated column if there is one). If it is a user creating an account through a web form, they get set as pending until they use the link in their email. The link in the email uses an activation code that allows me to do something like: </p> <pre><code>update user set status='active' activated=NOW() where code=:activation_code </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload