Page 1 of 1

Creating records using multiple selections from form

Posted: Wed May 22, 2002 11:00 am
by Crashin
Okay...I've beat my head over the bricks on this one, and so I now ask for help from you all. I've got a form with a multiple select element that I've named app_id[]. See code below:

Code: Select all

//generate applications drop down
$query_apps = "SELECT * FROM application ORDER BY app_name";
$result_apps = mysql_query($query_apps);
if(!$result_apps) {
	echo "<td>Could not get applications!</td>";
	exit;
&#125;
if(mysql_num_rows($result_apps) == 0) &#123;
	echo "<td><font class='small'>No applications setup - go to the <a href='app_entry.php'>Applications</a> page to setup.</font></td>";
	exit;
&#125;
else &#123;
	echo "<td>";
		echo "<select name='app_id&#1111;]' size='5' multiple>";
		while($row = mysql_fetch_array($result_apps)) &#123;
			echo "<option value='".$row&#1111;0]."'>".$row&#1111;1]."</option>";
		&#125;
		echo "</select>";
	echo "</td>";
&#125;
The variables are passed to a script on a separate page for entry into the table. Here is where the problem occurs. I want a new record created for each application chosen, but I'm not looping through the variables correctly (obviously). See code below:

Code: Select all

$kb_record_id = makeUniqID();
//if ok, insert into db's
$querya = "INSERT INTO kb_record (kb_record_id, question, resolution, tbd_manual, comp_manual, dateadd_manual, tbd_help, comp_help, dateadd_help, tbd_website, comp_website, dateadd_website, internal, recordno, date_entered, date_modified) VALUES ('$kb_record_id', '$question', '$resolution', '$man_tbd', '$man_comp', '$man_date', '$help_tbd', '$help_comp', '$help_date', '$web_tbd', '$web_comp', '$web_date', '$int_use', '$record_no', '$ent_date', '$mod_date')";
$resulta = mysql_query($querya);
if (!$resulta) {
	echo "Could not insert the record!";
	exit;
}

$count = count($app_id);

for ($i=0; $i<$count; $i++) {
	$queryb = "INSERT INTO complete_record (kb_record_id, app_id, cat_id, orig_user) VALUES ('$kb_record_id', '$app_id&#1111;$i]', '$cat_id', '$orig_user')";
	$resultb = mysql_query($resultb);
}
if (!$resultb) {
	echo $app_id&#1111;$i];
	echo "Could not create record!";
	exit;
}
The second insert command is the one in question, however I've included the first in case it's tied to the problem somehow. ANY help with this is GREATLY appreciated! :?

Nevermind...I'm a dumba**

Posted: Wed May 22, 2002 11:27 am
by Crashin
Hello all...again. Immediately following the posting of this message I discovered, much to my chagrin, that I was querying my result variable as opposed to my query variable. Ugh! Anyway, I wanted to leave this post up so that anyone with the same question might get some value out of it. Upon correcting the variable the insert worked perfectly. :oops: