SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Zealot
    Join Date
    Oct 2006
    Posts
    139
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Weird problem posting form variables in URL

    I have created a form through php that basically puts a check box against each of the results from a mysql query

    The form once finished looks like this

    <form name="selected" action="http://mydomain.com/index.php" method="get">
    <input type="checkbox" name="selected" value="1234" >
    <input type="submit" value="Select" >
    <input type="checkbox" name="selected" value="12345" >
    <input type="submit" value="Select" >
    <input type="checkbox" name="selected" value="123456" >
    <input type="submit" value="Select" >
    </form>

    When i output the code through php, it doesnt work,
    it posts to a url like this http://mydomain.com/index.php?selected=
    There is no selected value being passed through the url

    In firefox, when i refresh the page with a ticked checkbox, and try it it works

    In ie it doesnt work at all

    I really dont understand why it isnt working and would be v grateful for any help

    Cheers

  2. #2
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    The name value is "selected" on each one, they should be unique.

    When it gets to the other end PHP will just keep writing over each one ...

    Create an array of "selected"s if you like, or find away of giving them a unique names ..

    selected[1] = 1234

    OR

    selected_1 = 1234

  3. #3
    SitePoint Zealot
    Join Date
    Oct 2006
    Posts
    139
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Really strange because I have changed them so they are unique and i still get an empty var

    So you are saying that the name"selected" field in the <input> tag needs to be unqiue as well as in selected_1, selected_2 etc.

    It is even more strange because it works when i copy that form code directly into a fresh html document ??


    Im confused???

  4. #4
    SitePoint Addict
    Join Date
    Dec 2004
    Posts
    240
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try this code:
    PHP Code:
    <form name="from1" action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>" method="get">
    <input type="checkbox" name="selected1" value="1234" >
    <input type="submit" value="Select" >
    <input type="checkbox" name="selected2" value="12345" >
    <input type="submit" value="Select" >
    <input type="checkbox" name="selected3" value="123456" >
    <input type="submit" value="Select" >
    </form>
    <?php
    echo '<pre>'.print_r($_GET,true).'</pre>';
    ?>
    I think you'll see from the result of trying it what you do not understand. If not, please ask questions.

  5. #5
    SitePoint Zealot
    Join Date
    Oct 2006
    Posts
    139
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    still cant get it to work

    i can post the value i am trying to submit in the name field

    however it remains empty in the value field

    I have now made selected

    name="selected_'.$myid.'"

    still not working

    This does work when i pasted the outputted php source into a html doc so i know the output works

    it just wont work in my php application

  6. #6
    Who turned the lights out !! Mandes's Avatar
    Join Date
    May 2005
    Location
    S.W. France
    Posts
    2,496
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by doggybag View Post
    still cant get it to work
    Post your latest version of the code
    A Little Knowledge Is A Very Dangerous Thing.......
    That Makes Me A Lethal Weapon !!!!!!!!

    Contract PHP Programming

  7. #7
    SitePoint Zealot
    Join Date
    Oct 2006
    Posts
    139
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here is the code i am using to output the html
    <?php
    $content.=
    //Iterate over mysql results (this is a mysql array i am looping over)
    '<input type="checkbox" name="selected_'.$myid.'" value="'.$myid.'" >
    <input type="submit" value="select" >';

    //Form container
    echo '
    <form name="form1" action="/index.php" method="get"> ';
    echo $content;
    echo '
    </form>';
    ?>
    Here is the html it outputs

    <form name="form1" action="/index.php" method="get">


    <input type="checkbox" name="selected_64763943" value="64763943" >
    <input type="submit" value="select" >

    <input type="checkbox" name="selected_84929435" value="84929435" >
    <input type="submit" value="select" >

    <input type="checkbox" name="selected_64766049" value="64766049" >
    <input type="submit" value="select" >

    <input type="checkbox" name="selected_64760331" value="64760331" >
    <input type="submit" value="select" >

    <input type="checkbox" name="selected_64766051" value="64766051" >
    <input type="submit" value="select" >

    <input type="checkbox" name="selected_83223553" value="83223553" >
    <input type="submit" value="select" >

    <input type="checkbox" name="selected_84929437" value="84929437" >

    <input type="submit" value="select" >

    <input type="checkbox" name="selected_84929543" value="84929543" >
    <input type="submit" value="select" >

    <input type="checkbox" name="selected_83223563" value="83223563" >
    <input type="submit" value="select" >

    <input type="checkbox" name="selected_83223561" value="83223561" >
    <input type="submit" value="select" >

    <input type="submit" value="Select" >
    </form>

    Weird thing is, it is just a straight forward form

    When i refresh in firefox with the box checked it the submit button works

  8. #8
    SitePoint Zealot
    Join Date
    Oct 2006
    Posts
    139
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok so i have now fixed this

    it was another script that was being included at the top

    Cheers for all the help



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
  •