Jump to content

Recommended Posts

I am not able to test my code from where i am now, and I am not sure why my editor is underlining this code.

Any chance someone may be willing to help me find the issue?

It's underlining the if ($time) {

but obviously that doesn't always mean it's not before or after.

for ($loop=1;$loop<=3;$loop++) {
$time = $_POST['time-'.$loop];
if ($time) {
    $scheduleinsert = "INSERT INTO schedules (eventid, time, grades, room, notes) VALUES ('$eventid', '$time', '$grades', '$room', '$notes')";
    $schedule_result=mysql_query($scheduleinsert);

Thanks, any help would be appreciated.

 

Link to comment
https://forums.phpfreaks.com/topic/84704-insert-inside-for-loop/
Share on other sites

yes...

for ($loop=1;$loop<=3;$loop++) {
$time = $_POST['time-'.$loop];
if ($time) {
    $scheduleinsert = "INSERT INTO schedules (eventid, time, grades, room, notes) VALUES ('$eventid', '$time', '$grades', '$room', '$notes')";
    $schedule_result=mysql_query($scheduleinsert);

}

}

<?php

for ($i = 1; $i <= 3; $i++) {
    $time = $_POST['time-' . $i];

    if ($time) {
        $scheduleinsert = "INSERT INTO `schedules` (`eventid`, `time`, `grades`, `room`, `notes`) VALUES ('" .
            $eventid . "', '" . $time . "', '" . $grades . "', '" . $room . "', '" . $notes .
            "')";
        $schedule_result = mysql_query($scheduleinsert);
    }
}

?>

 

Just make sure you have the other variables defined.

I changed it to the following, realizing I had to add the loop part to those variables too, but I'm still getting the same thing.

It says parse error: expecting T_string or T_variable or T_NUM_STRING on line 21

 


for ($i = 1; $i <= 3; $i++) {
    $time = $_POST['time-' . $i];
    $grades = $_POST['grades-' . $i];
    $room = $_POST['room-' . $i];
    $notes = $_POST['notes-' . $i];
if ($time) {
        $scheduleinsert = "INSERT INTO `schedules` (`eventid`, `time`, `grades`, `room`, `notes`) VALUES ('" .
            $eventid . "', '" . $time . "', '" . $grades . "', '" . $room . "', '" . $notes .
            "')";
        $schedule_result = mysql_query($scheduleinsert);
    }
}

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.