definitely a loop will do the job.

on a form submission, you can get all the submitted fields/ values in
$_POST or $_GET array.

just, try 'print_r($_POST)', on top of your receiving script. you will
realise the scene behind. :)

then, get the size of the $_POST array and loop through the array
elements. a common data base function to insert the data will ease
your life further.


~viraj

On 5/10/06, Chris Grigor <[EMAIL PROTECTED]> wrote:
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

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Reply via email to