Is there an easier way of doing this?
| From: | Chris Grigor | Date: | Wed, 10 May 2006 08:49:20 +0000 |
| Subject: | Is there an easier way of doing this? | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-235859@lists.php.net to get a copy of this message | ||
morning all,
Is there an easier way of doing the following??
form1 submitting to form1.php
<input type="checkbox" name="1">
<input type="checkbox" name="2">
<input type="submit>
form1.php
<?php
$link = mysql_connect('host', 'user', 'pass') or die ("Connection failed:" . mysql_error());
mysql_select_db('yourdbname', $link) or die ("selection failed: " . mysql_error());
if(isset($_POST[1])) {
mysql_query("INSERT INTO menu (label) VALUES ('item 1 selected')");
}
else {
mysql_query("INSERT INTO menu (label) VALUES ('item 1 not selected')");
}
if(isset($_POST[2])) {
mysql_query("INSERT INTO menu (label) VALUES ('item 2 selected')");
}
else {
mysql_query("INSERT INTO menu (label) VALUES ('item 2 not selected')");
}
mysql_close($link);
?>
So my question is, if I have a form with 20 + items which can be checkboxes, when submitted do I need to go through each one and add it to the datasbase or maybe some kind of loop?.
Thank you
Chris