Jump to content

insert statement with checkboxes


Canman2005

Recommended Posts

Hi all

 

I have a series of checkboxes in a form, the code looks like

 

<form>
<input name="1" type="checkbox" id="1" value="1" />item 1<br />
<input name="2" type="checkbox" id="2" value="2" />item 2<br />
<input name="3" type="checkbox" id="3" value="3" />item 3<br />
<input name="4" type="checkbox" id="4" value="4" />item 4<br />
<input name="5" type="checkbox" id="5" value="5" />item 5<br />
<input type="button" value="submit" />
</form>

 

The above is generated from a QUERY on a table, so the list of checkboxes can be longer or shorter.

 

What I want to do is to run a query when the form is submitted and run a INSERT statement for all the checkboxes which were ticked

 

INSERT INTO `itemtable` SET `itemnum` = $_GET[''] AND `memberid` = $_SESSION['idnum']

 

So the value of the checkbox is inserted into `itemnum`, if 3 checkboxes were ticked, it would run that query 3 times for the ones which were ticked.

 

Does that make sense?

 

Any help would be ace

 

Thanks in advance

 

Dave

Link to comment
https://forums.phpfreaks.com/topic/93843-insert-statement-with-checkboxes/
Share on other sites

Hi

 

INSERT INTO `itemtable` SET `itemnum1` = $_GET['1'], `itemnum2` = $_GET['2'] , `itemnum3` = $_GET['3'] , `itemnum4` = $_GET['4'], `itemnum5` = $_GET['5']   AND `memberid` = $_SESSION['idnum']

make sure itemnum1, itemnum2, itemnum3, itemnum4, itemnum5 all have default values as 0.

Hi

 

I wanted to make each checkbox that is ticked into a seperate INSERT statement, the reason is that my database table that the data is being inserted into looks like

 

ID  |  MEMBERID  |  ITEMNUM

 

so an example data dump could look like

 

ID  |  MEMBERID  |  ITEMNUM

1      5433              2

2      5433              4

3      8965              8

4      5433              1

 

The list of checkboxes is generated with

 

<?php
$sql = "SELECT * FROM `tickboxes`";
$query = @mysql_query($sql,$connection) or die(mysql_error());
while ($row = mysql_fetch_array($query))
{
?>
<input name="<?php print $row['id']; ?>" type="checkbox" id="<?php print $row['id']; ?>" value="<?php print $row['id']; ?>" />item <?php print $row['id']; ?><br />
<?php
}
?>

 

So there could be 10 checkboxes or there could be 3 checkboxes

 

Does that make any sense? Kinda hard to explain

 

Thanks

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.