Jump to content

Inserting checkboxes with same data as different records


Bknvc1

Recommended Posts

I am not sure exactly how to do this or even if it is possible. Basically what I am doing is building an add product page that uses all the text boxes and menu boxes (these would be common for all the new products added) and loops through all the check boxes and inserts a new record for each checked check box with one click of the insert product button.

 

The form looks something like this:

 

<form id="form1" name="form1" method="POST">
	<p>Brand: <select name="select">
	  <option selected="selected">Select</option>
	  <option value="Ace">Ace</option>
	  <option value="Alba">Alba</option>
	  <option value="American Racing">American Racing</option>
      </select>
	</p>
	<p>Name: <input type="text" name="textfield" /></p>
	<p>
	<input name="Checkbox" id="Checkbox" type="checkbox" value="4x98" /> 4x98<br />
	<input name="Checkbox" id="Checkbox" type="checkbox" value="4x100" /> 4x100<br />
	<input name="Checkbox" id="Checkbox" type="checkbox" value="4x4.25 (4x108)" /> 4x4.25 (4x108)<br />
	<input name="Checkbox" id="Checkbox" type="checkbox" value="4x4.5 (4x114.3)" /> 4x4.5 (4x114.3)<br />
	</p>		
	<p><input type="submit" name="Submit" value="Insert" /></p>
      </form>

 

If there was two check boxes checked then I would want two records added and the only difference between the two records would be the value of the check box selected. I hope I have made what I am trying accomplish clear. I am willing to work with who every is willing to help me solve this issue. This would be such a time saver when adding products to the database.

 

Thanks,

Bknvc1

you have to have unique names for your check boxes plus value wont set on checkboxes

(also its bad css to use multiple instances of the same id name, use class)

 

My preference is to use an array

 

IE :

<input name="checkbox[4x98]" class="Checkbox" type"checkbox" />4x98<br />
<input name="checkbox[4x100]" class="Checkbox" type"checkbox" />4x100<br />
<input name="checkbox[4x108]" class="Checkbox" type"checkbox" />4x108<br />

in your catching script

<?PHP

if(isset($checkbox))
{
  foreach($checkbox as $k => $v)
  {
    echo $k."<br />";
  }
}
?>

 

I hope this helps.

 

:)

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.