Trying to check specific column values before inserting a new row. But a bit confused PDO's ON DUPLICATE KEY UPDATE
so, here is insert function below.
public function insert_schedule($user_id, $status, $content, $date, $time, $remarks, $created_at){
$sql = "INSERT INTO schedules (user_id, status, content, return_date, return_time, remarks, created_at) VALUES (?,?,?,?,?,?,?)
ON DUPLICATE KEY UPDATE user_id, created_at = VALUES(user_id, created_at)";
$stmt = $this->connect()->prepare($sql);
$stmt->execute([$user_id, $status, $content, $date, $time, $remarks, $created_at]);
}
I want to check created_at
and user_id
before insert a new row. if created_at
already exist on same user_id
than update that row. else, insert a new row. How can I fix the above function.