Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    Regular Coder
    Join Date
    May 2004
    Posts
    144
    Thanks
    0
    Thanked 0 Times in 0 Posts

    selecting a radio button with a session variable

    This is my code:

    PHP Code:
    $checked $_SESSION['empstatus'];
        
        echo 
    '<p>Employed<input type="radio" name="empstatus" value="employed"';  if ($checked "employed") { echo "SELECTED";} echo '>'
        echo 
    'Unemployed<input type="radio" name="empstatus" value="unemployed"';  if ($checked "unemployed") { echo "SELECTED";} echo '>'
        echo 
    'Retired<input type="radio" name="empstatus" value="retired"';  if ($checked "retired") { echo "SELECTED";} echo '>'
        echo 
    'Disabled<input type="radio" name="empstatus" value="disabled"';  if ($checked "disabled") { echo "SELECTED";} echo '>'
    it does not give me the session variable as being the selection checked, and i can echo the variable

    any help thanx in advance
    c.c.

  • #2
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,471
    Thanks
    8
    Thanked 1,085 Times in 1,076 Posts
    Change the equal signs in your "if" statements ...

    if ($checked === "employed")

  • #3
    Regular Coder
    Join Date
    May 2004
    Posts
    144
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thank you

    that means "is equal to and of the same type"

    correct?

    also,
    is the rest of the statement ok? (echo"SELECTED")
    Last edited by ClubCosmic; 04-01-2007 at 10:55 PM.

  • #4
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,027
    Thanks
    2
    Thanked 315 Times in 307 Posts
    one = assignment statement
    two == comparison operator, same value
    three === comparison operator, same value and same type
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • #5
    Regular Coder
    Join Date
    May 2004
    Posts
    144
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi all,

    This is a question that im posting again because i cant get it to work.

    Basically i have a form field using radio buttons. When submitted, it places the value in a session. I am trying to display the session value as SELECTED when I redisplay the form. instead it comes up blank.

    My question is can anyone look at the code and tell me if i am even doing this correctly. Maybe i should use a dropdown list but i would rather not.

    thankx again,
    c.c.

  • #6
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,027
    Thanks
    2
    Thanked 315 Times in 307 Posts
    Syntax for a "checked" radio button -
    Code:
    <input type="radio"  name="somename" value="somevalue" checked="checked">
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • #7
    Regular Coder
    Join Date
    May 2004
    Posts
    144
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thumbs up

    thanks again!!

  • #8
    Regular Coder
    Join Date
    Apr 2007
    Location
    U.S.A
    Posts
    129
    Thanks
    1
    Thanked 0 Times in 0 Posts

    PHP/music

    DELETE: Sorry wrong post.
    Last edited by awsomejoe23; 04-07-2007 at 07:01 PM. Reason: Wrong post.


  •  

    Posting Permissions

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