Re: Is there an easier way of doing this?
| From: | Barry | Date: | Wed, 10 May 2006 08:56:56 +0000 |
| Subject: | Re: Is there an easier way of doing this? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-235860@lists.php.net to get a copy of this message | ||
Chris Grigor schrieb:
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 SELECT ... INTOhttp://dev.mysql.com/doc/refman/4.1/en/ansi-diff-select-into-table.html -- Smileys rule (cX.x)C --o(^_^o) Dance for me! ^(^_^)o (o^_^)o o(^_^)^ o(^_^o)