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
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.

Link to comment
Share on other sites

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

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.