Jump to content

Need help with multiple html form arrays going to one SQL table


meisenheimer

Recommended Posts

In my form I have this:

<div class="confSub {conferences.confClass}">
                	<div>
                    	<input type="hidden" name="confPK" value="{conferences.confPK}">
           				<label>Conference Attended:</label><input size="85" name="conference[{conferences.confCounter}]" type="text" value="{conferences.conference}"/>
           				<label>Date:</label><input size="20" name="confDate[{conferences.confCounter}]" type="text" value="{conferences.confDate}"/>
                        <span class="example left"> ( YYYY-MM-DD )</span>
           				<label class="fullLabel clearfix">Description and Benefit to the University:</label>
           				<textarea name="confDesc[{conferences.confCounter}]" cols="90" rows="5">{conferences.confDesc}</textarea>
           				<input class="checkbox clearfix" name="confPres[{conferences.confCounter}]" value="yes" type="checkbox" {conferences.checkedConf}/>
                        	<label class="midLabel">Conference Presentation?</label>
           				<label class="clearfix">Title of Presentation:</label>
                        	<input class="pushLeft" size="85" name="confPresTitle[{conferences.confCounter}]" type="text" value="{conferences.ConfPresTitle}"/>
                    </div>
                </div>

 

I need to take the values of the same index for eachof five arrays ($_POST['conference'], $_POST['confDate'], $_POST['confDesc'], etc...) and insert/update them into a mysql table.  So conference[0], confDate[0], confDesc[0], confPres[0], and confPresTitle[0]  all need to go into the same index of their respective fields in the DB table.

 

If it was one array I could just do something like:

foreach($_POST['conference'] as $conference) 
	{
		// Update Conference
		$degreeQuery = "UPDATE CONFERENCES SET Conference = '".$conference."', StaffPK1 = '".$getPK1."' WHERE ConferencePK1 ='".$confID."'";
		$degreeQuery = mysql_query($degreeQuery);
	}

 

I'm having trouble with how to add a value from each array into the sql table.  I could do it through a different foreach loop for each array and iterate through all foreach loops with another loop, but that doesn't seem very efficient.  I'd like to do it with one sql statement for each set of "conference" data.

 

Thanks in advance,

Shannon

 

Link to comment
Share on other sites

Here is one option:

 

foreach($_POST['conference'] as $index => $conference) 
	{
		// Update Conference
                        // Access $_POST['confDate'][$index], $_POST['confDesc'][$index], etc etc.  You can use either $conference or $_POST['conference'][$index]
		$degreeQuery = "UPDATE CONFERENCES SET Conference = '".$conference."', StaffPK1 = '".$getPK1."' WHERE ConferencePK1 ='".$confID."'";
		$degreeQuery = mysql_query($degreeQuery);
	}

Link to comment
Share on other sites

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.