I am writing a plugin for WordPress, which should check if a mysql entry already exists.
If it does not exist WordPress should insert the entry into the table. This part works as I expected.
However, if there already is an entry in the mysql table, WordPress should update the table, but this does not work.
The code I am using for this is the following code:
$wpdb->query($wpdb->prepare("UPDATE $table_name SET time=$current_timestamp WHERE userid=$userid"));
The variables I use in this query are correct, because they are successfully used to insert into the table, but somewhere along the way something goes wrong with the updating function.
Can somebody please tell me what I am doing wrong here?
What is the right way to go about this?
the value of column
time must be enclosed with
$wpdb->query($wpdb->prepare("UPDATE $table_name SET time='$current_timestamp' WHERE userid=$userid"));
Answered By – John Woo
Answer Checked By – Katrina (BugsFixing Volunteer)