Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 09-12-2012, 10:08 PM   PM User | #1
Vigilante23
New Coder

 
Join Date: Aug 2012
Posts: 29
Thanks: 5
Thanked 1 Time in 1 Post
Vigilante23 is an unknown quantity at this point
Capturing checkbox value

I posted this in the mysql thread as well but thought maybe this is a more appropriate place seeing as how i know which sql query to run.

I have a list of names and email with check boxes beside em.

My Page

I want to be able to select certain lines then move them to another table.
Vigilante23 is offline   Reply With Quote
Old 09-12-2012, 10:37 PM   PM User | #2
Len Whistler
Senior Coder

 
Len Whistler's Avatar
 
Join Date: Jul 2002
Location: Vancouver, BC Canada
Posts: 1,323
Thanks: 26
Thanked 100 Times in 100 Posts
Len Whistler is on a distinguished road
Why do you want to do this? I can't figure out why some rows would be moved to another table. Why not add a column that defaults to 1, if those rows should be singled out then change the value to 0.






----
__________________
Leonard Whistler
Len Whistler is offline   Reply With Quote
Old 09-12-2012, 10:44 PM   PM User | #3
Vigilante23
New Coder

 
Join Date: Aug 2012
Posts: 29
Thanks: 5
Thanked 1 Time in 1 Post
Vigilante23 is an unknown quantity at this point
I'm pretty new to this. I'm not exactly sure what you said would do? Are you talking about essentially hiding them by giving them a different value until activated?

What I want to do is create a list of names of people to invite to something then they can come confirm that they are coming and add their name to a list of confirmed guests. Can I accomplish this through your method?
Vigilante23 is offline   Reply With Quote
Old 09-12-2012, 10:51 PM   PM User | #4
Len Whistler
Senior Coder

 
Len Whistler's Avatar
 
Join Date: Jul 2002
Location: Vancouver, BC Canada
Posts: 1,323
Thanks: 26
Thanked 100 Times in 100 Posts
Len Whistler is on a distinguished road
Quote:
Originally Posted by Vigilante23 View Post
I'm pretty new to this. I'm not exactly sure what you said would do? Are you talking about essentially hiding them by giving them a different value until activated?

What I want to do is create a list of names of people to invite to something then they can come confirm that they are coming and add their name to a list of confirmed guests. Can I accomplish this through your method?
You would need three tables.

Code:
USER
user_id | name | email
0001 | ben | ben@hotmail.com
0002 | ken |  ken@hotmail.com

EVENT
event_id | event
001 | Boat Ride
002 | Shopping


EVENT_ATTENDIES
event_id | user_id
001 | 0002
001 | 0001
002 | 0001
__________________
Leonard Whistler

Last edited by Len Whistler; 09-12-2012 at 10:58 PM..
Len Whistler is offline   Reply With Quote
Old 09-12-2012, 11:23 PM   PM User | #5
Vigilante23
New Coder

 
Join Date: Aug 2012
Posts: 29
Thanks: 5
Thanked 1 Time in 1 Post
Vigilante23 is an unknown quantity at this point
Quote:
Originally Posted by Len Whistler View Post
You would need three tables.

Code:
USER
user_id | name | email
0001 | ben | ben@hotmail.com
0002 | ken |  ken@hotmail.com

EVENT
event_id | event
001 | Boat Ride
002 | Shopping


EVENT_ATTENDIES
event_id | user_id
001 | 0002
001 | 0001
002 | 0001
Ok I see what you did there. But how do I capture a string with a checkbox?
Vigilante23 is offline   Reply With Quote
Old 09-13-2012, 01:37 AM   PM User | #6
Len Whistler
Senior Coder

 
Len Whistler's Avatar
 
Join Date: Jul 2002
Location: Vancouver, BC Canada
Posts: 1,323
Thanks: 26
Thanked 100 Times in 100 Posts
Len Whistler is on a distinguished road
Quote:
Originally Posted by Vigilante23 View Post
Ok I see what you did there. But how do I capture a string with a checkbox?

The selected boxes are added to an array, and you retrieve the values with a foreach loop. You need square braces around the name value in the form.

PHP Code:
name="color[]" 
PHP Code:
<?php
if (isset($_POST['submit'])) {
$color $_POST['color'];
foreach (
$color as $value){
echo 
"You checked: $value<br>";
}
}


$colors = array('blue','green','black','gold','silver','white','purple','red');
echo 
"<form method=\"post\" action=\"test.php\">";
foreach (
$colors as $color){
echo 
"<input type=\"checkbox\" name=\"color[]\" value=\"$color\">$color<br>";
}
echo 
"<input type=\"submit\" value=\"Pick a Color\" name=\"submit\">";
?>

Ouput
Code:
You checked: black
You checked: white
You checked: red
__________________
Leonard Whistler

Last edited by Len Whistler; 09-13-2012 at 01:44 AM..
Len Whistler is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 10:46 AM.


Advertisement
Log in to turn off these ads.