Jump to content

[SOLVED] Problem with for loop


jmr3460

Recommended Posts

Why doesn't this work right. I have a calendar. I am trying to allow people to insert multiple day events. The single day insert worked fine so I went to work on it and as soon as I added this for loop the day I click on to add an event becomes the number of times that the for loop loops. and the number of days that I pick is the day that the event is added to.

here is my loop:

if ($_POST) {
//start looking for multiple days here
$m = $_POST["m"];
$d = $_POST["d"];
$y = $_POST["y"];
$i = $_POST['num_days'];
for ($d=1; $d <= $i; $d++) {

$event_date = $y."-".$m."-".$d;
$insEvent_sql = "INSERT INTO calendar_events (id, event_title, event_shortdesc, event_start) VALUES('', '".$_POST["event_title"]."', '".$_POST["event_shortdesc"]."', '$event_date')";
$insEvent_res = mysqli_query($mysqli, $insEvent_sql) or die(mysqli_error($mysqli));
}
}

I really thought that a for loop is the way to go. Thanks for any help.

Link to comment
https://forums.phpfreaks.com/topic/175077-solved-problem-with-for-loop/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.