Results 1 to 3 of 3
  1. #1
    Join Date
    Jul 2003
    Posts
    1

    Unanswered: 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....

    <?php
    if (isset($_GET['mod']) && $_GET['mod'] == "1")
    { ?>
    <input type="radio" NAME="user_gender" value="1" checked><font face="Verdana" size="1">Male
    <input type="radio" NAME="user_gender" value="2"><font face="Verdana" size="1">Female
    <? }

    else

    if (isset($_GET['mod']) && $_GET['mod'] == "2")
    { ?>
    <input type="radio" NAME="user_gender" value="1"><font face="Verdana" size="1">Male
    <input type="radio" NAME="user_gender" value="2" checked><font face="Verdana" size="1">Female
    <? }
    ?>

  2. #2
    Join Date
    Jul 2003
    Posts
    2

    Probable Causes to Your Problem

    Hi,

    <?php
    if (isset($_GET['mod']) && $_GET['mod'] == "1")
    { ?>
    <input type="radio" NAME="user_gender" value="1" checked><font face="Verdana" size="1">Male
    <input type="radio" NAME="user_gender" value="2"><font face="Verdana" size="1">Female
    <? }

    else

    if (isset($_GET['mod']) && $_GET['mod'] == "2")
    { ?>
    <input type="radio" NAME="user_gender" value="1"><font face="Verdana" size="1">Male
    <input type="radio" NAME="user_gender" value="2" checked><font face="Verdana" size="1">Female
    <? }
    ?>

    Looks like pretty neat code. Good job...

    The most probable reasons as to why you are experiencing the problems you mentioned is BECAUSE when you update the form, its submits the form to the page and $_GET['mod'] makes sense. But when you just open the page without submitting the form a single time, $_GET['mod'] DOESN'T EXIST.
    So you have to add another CHECK condition that if the user hasn't submitted the form, it should just show the VALUES FROM THE DATABASE.

    You can perhaps shorten your code if you just print "checked" or "" in the <input> tag itself. Here's an example

    <input type="radio" NAME="user_gender" value="1" <?php if($_GET['mod']=="1") echo "checked"; ?> ><font face="Verdana" size="1">

    There you go. I hope this helps your cause.
    Good Luck

  3. #3
    Join Date
    Aug 2003
    Posts
    3
    As a suggestion for a way to retain this information across time without having to do a db lookup every page load, you might check out sessions. Your problem becomes trivial... assuming you get the sessions up and running as intended ;)

Posting Permissions

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