Re: Is there an easier way of doing this?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




for ($i = 1; $i <= 20; $i++){
  if (isset($_POST[$i])){
    //insert blah blah blah
  }
}

Also, I don't think '1' is valid NAME for HTML specification.

You could use:

NAME="menu[1]"

Then in PHP:

$menu = $_POST['menu'];

for ($i = 1; $i <= 20; $i++){
  if (isset($menu[$i])){
  }
}

And, of course, you need to scrub your data.

http://phpsec.org

On Wed, May 10, 2006 3:49 am, Chris Grigor 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
>
>


-- 
Like Music?
http://l-i-e.com/artists.htm

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


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux