Results 1 to 9 of 9

Thread: passing variables through a form

  1. #1
    Join Date
    Sep 2010
    Posts
    8
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default passing variables through a form

    This is what I want to happen:

    if "one" is the text in the first text field, and the first button is clicked, post.php returns 1one

    if "two" is the text in the second text field, and the second button is clicked, post.php returns 2two.

    This is what happens right now:

    the first button returns "2" regardless of what the input field is.

    the second button works as I want

    This is the code

    designers.php

    PHP Code:
    <?php 
    $result 
    mysql_query("SELECT * FROM designers");

    $designercounter 1;
    while(
    $row mysql_fetch_array($result)){
        
        
    $name ='designer'.$designercounter;
        echo
    "<div id='header'><p>" $row['designer_name'] . "</p></div>";
        echo
    "<form action = 'post.php' method ='POST' >";
        echo
    "<input type='submit' name='submit' value = 'Change name'>";
        echo
    "<input type='text' name='designername' size='30' >";
        echo
    "<input type='hidden' name='pasedvariable' value='".$designercounter."'> </form>";
        
        
    $designercounter++ ;
    }

    ?>
    post.php

    PHP Code:
    <?php

    $designerid 
    $_POST['pasedvariable'];
    $designername $_POST['designername'];
    echo 
    $designerid;
    echo 
    $designername;
        
    ?>
    Any help or guidance would be appreciated
    Last edited by mrabin; 01-03-2011 at 12:06 AM. Reason: fixing up html

  2. #2
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    I don't completely understand what you want, isn't it as simple as:
    PHP Code:
    if($_POST['first'] == "one" && isset($_POST['first_button'])){ echo "1one"; }

    if(
    $_POST['second'] == "two" && isset($_POST['second_button'])){ echo "2two"; } 
    Last edited by Nile; 12-30-2010 at 09:57 PM.
    Jeremy | jfein.net

  3. The Following User Says Thank You to Nile For This Useful Post:

    mrabin (01-02-2011)

  4. #3
    Join Date
    Sep 2010
    Posts
    8
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    the reason that I'm echoing those two is just to test that they've been properly passed to post.php, which isn't the case right now.

    I want the values that are in 'designername' and 'pasedvariable' to be displayed

    to me it seems logical that when I click on the first button, post.php would echo 1($designercounter = 1 for the first iteration of the while loop) followed by what is in the 'designername' textField.

    but instead it just echos 2, which is $designercounter for the second iteration of the while loop.

    Here's the link, http://www.unlikerabi.com/envied/adm...ddesigners.php

    sorry for being a bit unclear with the original post.

  5. #4
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    The page you linked to is asking me for a username and a password
    Jeremy | jfein.net

  6. #5
    Join Date
    Sep 2010
    Posts
    8
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    Ah yes, sorry. Should be available now.

  7. #6
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    For one, your HTML is invalid. Fix that up:
    Code:
    echo"<input type='hidden' name='pasedvariable' value='".$designercounter."' /></form>";
    http://validator.w3.org/check?uri=ht...Inline&group=0
    Jeremy | jfein.net

  8. #7
    Join Date
    Dec 2010
    Location
    Hyderabad, India
    Posts
    16
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default

    It works for me properly. You should just make this thread "Solved".

  9. #8
    Join Date
    Sep 2010
    Posts
    8
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    Thanks for the help. Nile you where right, that's all I had to change, I'll start using the html validator for everything.

  10. #9
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    No problem, I'm glad to help

    Here on DD, we like to keep things organized. In an effort to do so, you have the option to set a thread to resolved when an issue is fixed. To make the status of the thread resolved:
    1. Go to your first post
    2. Edit your first post
    3. Click "Go Advanced"
    4. In the dropdown next to the title, select "RESOLVED"
    Jeremy | jfein.net

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
  •