I am using a MySQL query from inside a WordPress custom plugin. I am submitting two values when posting. I want to update the time column if the user exists in the database.
Here is my code
function main()
{
if (isset($_REQUEST)) {
global $wpdb;
$taskTime = $_REQUEST["task_current_time"];
$taskTitle = $_REQUEST["task_current_title"];
$select_all_current = $wpdb->prepare("SELECT * FROM $this->tablenamev2 WHERE task_current_title = '$taskTitle'");
if ($wpdb->get_results($select_all_current)) {
var_dump("USER EXIST");
$wpdb->prepare("UPDATE $this->tablenamev2 SET task_current_time = '$taskTime' WHERE task_current_title = '$taskTitle'");
return;
} else {
var_dump("USER DOES NOT EXIT!!!");
$wpdb->query("INSERT INTO $this->tablenamev2 (task_current_time, task_current_title) VALUES ('$taskTime', '$taskTitle')");
die();
}
}
}
2
Answers
The mistake was in $select_all_current = $wpdb->prepare() and instead I replaced it with $wpdb->query();
Thank you for ur help!
I have modified your code for update and insert(hope it helps)….
Let me know if it working..