SitePoint Sponsor

User Tag List

Results 1 to 10 of 10

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    Apr 2002
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Angry Sending multiple values for a single variable

    <form action=....>
    ---
    <input type=checkbox name=colour value=red>Red
    <input type=checkbox name=colour value=yellow>Yellow
    <input type=checkbox name=colour value=black>Black
    <input type=checkbox name=colour value=white>White
    ---
    </form>

    Anytime I submit the form, only one value gets sent even after checking all the boxes. I tried using Perl/CGI for the target script and it worked fine. What am I doing wrong using php as the target script?

  2. #2
    FreeBSD The Power to Serve silver trophy pippo's Avatar
    Join Date
    Jul 2001
    Location
    Italy
    Posts
    4,514
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    I think that you have to add square brackets as:

    PHP Code:
    <?php
    <input type="checkbox" name="colour[]" value="red">Red 
    ?>
    H.T.H.!
    Mr Andrea
    Former Hosting Team Advisor
    Former Advisor of '03

  3. #3
    SitePoint Member
    Join Date
    Apr 2002
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Pippo, your suggestion didn't quite work, u know?

  4. #4
    Happy Holidays !! Paul S's Avatar
    Join Date
    Mar 2001
    Location
    Mexico
    Posts
    1,287
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This should work
    PHP Code:
    <?php
     
    if ($_GET['submit'] != ''
         foreach (
    $_GET['colour'] as $v)
            echo 
    $v,'<br>';
    ?>

    <form action="<?=$_SERVER['PHP_SELF']?>"> 
    --- 
    <input type="checkbox" name="colour[]" value="red">Red 
    <input type="checkbox" name="colour[]" value="yellow">Yellow 
    <input type="checkbox" name="colour[]" value="black">Black 
    <input type="checkbox" name="colour[]" value="white">White 
    <input type="submit" name="submit" value="submit">
    ---
    </form>
    Paul

  5. #5
    FreeBSD The Power to Serve silver trophy pippo's Avatar
    Join Date
    Jul 2001
    Location
    Italy
    Posts
    4,514
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    So my suggestion to add the square brackets was right...

    Mr Andrea
    Former Hosting Team Advisor
    Former Advisor of '03

  6. #6
    Happy Holidays !! Paul S's Avatar
    Join Date
    Mar 2001
    Location
    Mexico
    Posts
    1,287
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by pippo
    So my suggestion to add the square brackets was right...

    It was close but it's not right. Try it, it'll cause a syntax error.

    Paul

  7. #7
    Making a better wheel silver trophy DR_LaRRY_PEpPeR's Avatar
    Join Date
    Jul 2001
    Location
    Missouri
    Posts
    3,428
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by Paul S
    It was close but it's not right. Try it, it'll cause a syntax error.
    what do you mean?
    - Matt ** Ignore old signature for now... **
    Dr.BB - Highly optimized to be 2-3x faster than the "Big 3."
    "Do not enclose numeric values in quotes -- that is very non-standard and will only work on MySQL." - MattR

  8. #8
    Happy Holidays !! Paul S's Avatar
    Join Date
    Mar 2001
    Location
    Mexico
    Posts
    1,287
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by DR_LaRRY_PEpPeR
    what do you mean?
    I was referring to pipo's code,
    PHP Code:
    <?php
    <input type="checkbox" name="colour[]" value="red">Red 
    ?>
    Paul

  9. #9
    Making a better wheel silver trophy DR_LaRRY_PEpPeR's Avatar
    Join Date
    Jul 2001
    Location
    Missouri
    Posts
    3,428
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yeah, i knew that. i didn't know what you meant by "syntax error." but now i see it: 'cause it's in <?php tags. doh! didn't even realize that last night. sorry.

  10. #10
    FreeBSD The Power to Serve silver trophy pippo's Avatar
    Join Date
    Jul 2001
    Location
    Italy
    Posts
    4,514
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ahh,
    I see that now...obviously it was not right...thank you for the correction,
    my aim was to show the usage of the brackets and I usually put <?php ?> when I start putting code,
    so I forget to remove them.
    Mr Andrea
    Former Hosting Team Advisor
    Former Advisor of '03


Bookmarks

Posting Permissions

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