I have searched and tried a variety of solutions but don't seem to be getting this. I have an event which happens every week on the same day of the week. I want to be able to add it to the MySQL database so that the same exact info goes in for 16 different weeks, meaning only the eventDate field will change.
Currently the form to add the event has a checkbox labelled 'recurring' and a date field for the initial event date. I am then trying to insert the initial record with the date entered before looping through another 15 inserts with the date set to be 1 week later each time but the rest of the data is as originally entered.
I have assigned variables from the form submission and then am doing the insert according to whether the 'recurring' field is set to 1. I am not getting an error but the event is being entered with a date of 0000-00-00. It works fine when I remove the 'recurring' test and simply do a straight insert.
$id=$_POST["eventid"];
$eventHeadingTemp = $_POST["eventHeading"];
$eventHeading = mysql_escape_string($eventHeadingTemp);
$eventTypeId = $_POST["eventTypeId"];
$eventInfoTemp = $_POST["eventInfo"];
$eventInfo = mysql_escape_string($eventInfoTemp);
$eventDate = $_POST["eventDate"];
$recurring = $_POST["recurring"];
$eventStartTime = $_POST["eventStartTime"];
$eventImagesDelete=$_POST["eventImagesDelete"];
if ($id==0) {
if ($recurring==1) {
$SQL="INSERT INTO events (eventHeading, eventTypeId, eventInfo, eventDate, recurring, eventStartTime, eventImage, eventThumb) VALUES ('$eventHeading', '$eventTypeId', '$eventInfo', '$eventDate', '$recurring', '$eventStartTime', '$eventImage', '$eventThumb')";
for ($i=0; $i<16; $i++) {
$eventDate = strtotime('+1 week' , $eventDate);
$SQL="INSERT INTO events (eventHeading, eventTypeId, eventInfo, eventDate, recurring, eventStartTime, eventImage, eventThumb) VALUES ('$eventHeading', '$eventTypeId', '$eventInfo', '$eventDate', '$recurring', '$eventStartTime', '$eventImage', '$eventThumb')";
}
}
else {
$SQL="INSERT INTO events (eventHeading, eventTypeId, eventInfo, eventDate, recurring, eventStartTime, eventImage, eventThumb) VALUES ('$eventHeading', '$eventTypeId', '$eventInfo', '$eventDate', '$recurring', '$eventStartTime', '$eventImage', '$eventThumb')";
}
}
UPDATE: I see this question being viewed occasionally but not answered just yet so want to add that if I didn't clearly present the problem please feel free to say so and ask for more / better information. Thanks so much...