SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Member
    Join Date
    Jul 2003
    Location
    ontario, canada
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    radio button retain information on an update records page

    i have a completely userbased website with registered members that have access to adding information for several sections of my page. one of the sections is an area to update personal profile information. On that member's only page, there are radio buttons that set the users gender. Selecting either male or female and clicking the update information button, will change the user's gender perfectly, however, once going back in later to change whatever information, the user's gender is always selecting female, even if the user has selected male. here is my code, hopefully someone can shed some light on this matter....

    <?
    echo "<input type=\"radio\" NAME=\"user_gender\" value="1" ".($_GET['mod'] == "1" ? "checked" : "")."><font face=\"Verdana\" size=\"1\">Male\n";

    echo "<input type=\"radio\" NAME=\"user_gender\" value="2" ".($_GET['mod'] == "2" ? "checked" : "")."><font face=\"Verdana\" size=\"1\">Female";
    ?>

  2. #2
    if($awake){code();} PHP John's Avatar
    Join Date
    Jul 2002
    Location
    Along the Wasatch Fault line.
    Posts
    1,771
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Your "$_GET['mod']" should read "$_GET['user_gender']"

    Assuming, of course, that your <form> method is "get".
    John

  3. #3
    SitePoint Member
    Join Date
    Jul 2003
    Location
    ontario, canada
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    my form tag is post...

    i just tried it with get and once i submitted the form, it cleared all my feilds, and didnt do anything

  4. #4
    if($awake){code();} PHP John's Avatar
    Join Date
    Jul 2002
    Location
    Along the Wasatch Fault line.
    Posts
    1,771
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Alright. Is this form submitting to a different script or to itself?

    If you are submitting it to itself then change to this and try it:

    $_POST['user_gender']
    John

  5. #5
    SitePoint Member
    Join Date
    Jul 2003
    Location
    ontario, canada
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i actually just tried that with all the feilds, would only doing it to the problem with the gender feild work?

  6. #6
    if($awake){code();} PHP John's Avatar
    Join Date
    Jul 2002
    Location
    Along the Wasatch Fault line.
    Posts
    1,771
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What you have to realize is that the "name" in the form element becomes the key to the $_GET or $_POST array.

    Therefore take a look at the examples below.

    This example would return the entered value for the input field:
    PHP Code:
    <form action="'.$_SERVER['PHP_SELF'].'" method="post">
      <
    input type="text" name="firstName" value="'.$_POST['firstName'].'" />
      <
    input type="submit" name="do" value="Submit" />
    </
    form
    The following would not, but would return nothing to the text field:
    PHP Code:
    <form action="'.$_SERVER['PHP_SELF'].'" method="post">
      <
    input type="text" name="firstName" value="'.$_POST['mod'].'" />
      <
    input type="submit" name="do" value="Submit" />
    </
    form
    John


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
  •