View Full Version : PHP with check boxes

05-06-2009, 10:20 PM
Hi there everybody,

I'm sure that this has been asked before, but I've looked through and can't find an answer and I'm running out of time.

I have a site that I'm building for uni and have some check boxes. When the check boxes are checked, I need the username of the user to be posted onto another page. Is this possible? I have no idea how to do it, since I don't understand php at all.

Also, on another page, where these names are posted there are check boxes with those names. I need it so that when the user checks the boxes and clicks submit, the names of the checked ones show on another page.

Any help at all would be very grateful, like I say, I'm running out of time and the whole thing is stressing me out.

Thank you in advance

05-06-2009, 10:40 PM
a simple example:

function form()
echo '<form action="" method="post">';

for ($i = 1; $i <= 5; $i++)
echo '<input type="checkbox" name="users[]" value="' . $i . '"'; if (isset($_POST['users']) && in_array($i, $_POST['users'])) {echo ' checked';} echo '> user ' . $i . '<br>';

echo '
<input type="submit" name="submit" value="submit">

if (!isset($_POST['submit']))

if (isset($_POST['users'])) {echo 'you checked the following users: ' . implode(', ', $_POST['users']);}
else {echo 'you did not check any users';}

05-07-2009, 10:39 AM
Thank you for the code.

That's a great help to get me started.

05-07-2009, 04:32 PM
I just want to notice that you can also use array-style names of the input fields such as user[preferences] and user[password].