Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder
    Join Date
    Aug 2012
    Posts
    38
    Thanks
    8
    Thanked 1 Time in 1 Post

    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.

  • #2
    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
    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

  • #3
    New Coder
    Join Date
    Aug 2012
    Posts
    38
    Thanks
    8
    Thanked 1 Time in 1 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?

  • #4
    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
    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
    Last edited by Len Whistler; 09-12-2012 at 10:58 PM.
    Leonard Whistler

  • #5
    New Coder
    Join Date
    Aug 2012
    Posts
    38
    Thanks
    8
    Thanked 1 Time in 1 Post
    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?

  • #6
    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
    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
    Last edited by Len Whistler; 09-13-2012 at 01:44 AM.
    Leonard Whistler


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •