Re: [PHP-DB] checkboxes

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

 



Joe Harman wrote:
Well.. i just got done doing something like what you are trying to
accomplish... you will need to name your check boxes like so :
name="completed[]"

when the form is submitted, I use something like this and shove it
into a field in the database:

if($_POST['completed'] <> NULL)
{
// This makes one string of all the check boxes
$completed_separated = implode(":", $_POST['completed']);
}
else
{
$comma_separated = NULL;
}

anyhow... use explode to get thte values out...
why would you implode and explode it in the same piece of code? sounds pretty... useless... to me. I'd just say, loop over the array, and do whatever you want with it.

<input name="array_name[]">
is equivalent to $_POST['array_name'][] (Or $_GET['array_name'][]).

<input name="array_name[key_126]">
is equivalent to $_POST['array_name'][126] (Or $_GET['array_name'][126]).

etc. etc.
Not that hard it seems ;)
not sure how you are
using this... but i made each check box equal to a value when checked
i.e. 23, 34

so, not sure if this is the right way to do it, but i find it to be a
pretty simple solution for my uses.

cheers




On Fri, 21 Jan 2005 16:47:11 -0500, Hutchins, Richard <Richard.Hutchins@xxxxxxxxxxxxxx> wrote:

You can't just echo out an array. You have to either use print_r() or
iterate over it with a while or for...next loop. But if you just want to see
what's in the array, print_r() it.

As to why it doesn't bring over the other checkboxes...

If you have (pseudocode)
<html>
<form name="myform" method="post" action="myupdate.php">
<input type="checkbox" name="completed[]" value="value1">&nbsp;Checkbox 1
<input type="checkbox" name="completed[]" value="value2">&nbsp;Checkbox 2
<input type="checkbox" name="completed[]" value="value3">&nbsp;Checkbox 3
</form>
</html>

And you check the first two checkboxes, then the resulting array will be
(pseudocode again):
completed(value1,value2)

And from there, you just access the array contents as you would with any
other multidimensional array.

If you don't check anything on the page, then the array will be empty and, I
think, won't even be sent in the $_POST array. I'm sure somebody will
correct me there if my memory has failed me.

-----Original Message-----
From: Craig Hoffman [mailto:choffman@xxxxxxxxxx]
Sent: Friday, January 21, 2005 4:32 PM
To: php-db@xxxxxxxxxxxxx
Cc: Richard Hutchins
Subject: Re: [PHP-DB] checkboxes

I've tried that and it still doesn't bring over the other checkboxes
that have been checked.  Plus when I echo it out I get
Array  instead of the variable name.

On Jan 21, 2005, at 3:14 PM, Hutchins, Richard wrote:


Probably all you need to do is name your checkboxes as an array thusly:

name="completed[]"

Then you can access the array on your update page and do whatever you
wish
with it.

Hope this helps.

Rich

-----Original Message-----
From: Craig Hoffman [mailto:choffman@xxxxxxxxxx]
Sent: Friday, January 21, 2005 4:03 PM
To: php-db@xxxxxxxxxxxxx
Subject: [PHP-DB] checkboxes


I have a form that display's a checkbox if the value is NULL. The form is in a do... while loop, so the user may check multiple checkboxes. I am trying to pass the variable of each checkboxes to an update statement in MySQL. THe problem is I am only getting one of the checkboxes, even if all of them are checked. Here is my code block, any help would be great. - Craig

//From form page
<form>
 <input type='checkbox' name='completed' value='Done' >
</form>

//MySQL Update Page
$email = $_POST['email'] == $route;
             $completed = $_POST["completed"] == $route;
              $route_name = trim($_POST["route_name"]) == $route;
             $user_id = $_POST['user_id'] == $route;
                     $id = $_POST['id'] == $route;

$route = array(id => "$_POST[id]", completed => "$_POST[completed]",
route_name => "$_POST[route_name]", user_id => "$_POST[user_id]");

            foreach ($route as $key => $values) {
                   echo("<br />");
                   echo $values;
                  //MySQL Update statement will go here.
             }

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

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


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



-- 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