Canman2005 Posted March 1, 2008 Share Posted March 1, 2008 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 Quote Link to comment Share on other sites More sharing options...
werty37 Posted March 1, 2008 Share Posted March 1, 2008 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. Quote Link to comment Share on other sites More sharing options...
Canman2005 Posted March 1, 2008 Author Share Posted March 1, 2008 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 Quote Link to comment Share on other sites More sharing options...
Canman2005 Posted March 1, 2008 Author Share Posted March 1, 2008 Thanks, I have managed to solve this Quote Link to comment Share on other sites More sharing options...
ohdang888 Posted March 1, 2008 Share Posted March 1, 2008 what does this: SET `itemnum1` = $_GET['1'] do? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.