Jump to content

Recommended Posts

I have a two part form, because I have to insert into two different tables.

 

First table is event information.  Second table is the intended audience.  If first part of the form inserts successfully into events table, it moves on to process the audience table.

 

If no selections are made for the audience, it errors out as "Warning: Invalid argument supplied for foreach()"

 

If a selection is made, it works fine.  I don't want to make selecting a target audience a requirement so I want it to forward to the confirmation page as if I did make a selection.

 

if (empty($errors)) {

	$insert_program = "INSERT INTO programs (name, coordinator, description, instructions, online_option, session_limit) VALUES ('$n','$c','$d','$i','$oo','$sl')";
	$result_program = mysql_query($insert_program) OR die ('Could not create the new program.');

	$id = mysql_insert_id();

	if ($insert_program) {

		foreach($_POST['audience'] as $aid) {

			if ($aid > 0) {

				$insert_audience = "INSERT INTO programs_audiences (program_id, audience_id) VALUES ('$id','$aid')";
				$result_audience = mysql_query($insert_audience) OR die ('Could not insert the intended audiences.');

				if ($insert_audience) {
					header("Location: program_created.php?id=$id");
					exit;
				}

			} else if ($aid < 1) {

				header("Location: program_created.php?id=$id");
				exit;
			}

		}

	}

}

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.