0

I'm stuck on a simple MYSQL UPDATE statement; selecting an ID from the database, and then updating a record WHERE ID = $ID. Code:

$searchDates = ('SELECT * FROM booking_event WHERE subject != "Closed" AND is_reminded IS NULL AND DATE_ADD(NOW(), INTERVAL 2 DAY) >= `starting_date_time` AND NOW() <= `starting_date_time`'); 

$result = mysql_query($searchDates) or die (mysql_error());

while ($row = mysql_fetch_array($result)) {
  $id = $row['event_id'];

mysql_query("UPDATE booking_event SET is_reminded = 1 WHERE event_id = '$id'") or die (mysql_error()); 

}

For some reason it won't update with the ID selected from the database - I've tried using a testID variable and it works fine.

Any help would be appreciated Thanks!

0

2 Answers 2

2

You can do this in one query like so:

UPDATE booking_event b1
INNER JOIN
(
    SELECT * 
    FROM booking_event 
    WHERE subject != "Closed" 
      AND is_reminded IS NULL 
      AND DATE_ADD(NOW(), INTERVAL 2 DAY) >= starting_date_time 
      AND NOW() <= starting_date_time
) b2
SET t1.is_reminded = 1 WHERE b1.event_id = b2.event_id
Sign up to request clarification or add additional context in comments.

Comments

1

PHP variables are case sensitive. Most likely your column name in MYSQL will be something like Event_Id or any other casing. Using SELECT * will return the actual name, so to fetch it you would need $id = $row['Event_Id'];

Best thing to be sure you dont have a casing problem, use:

SELECT event_id FROM ....

and then $id = $row['event_id']; will work.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.