Jump to content

PHP Radio button options issue


stelthius

Recommended Posts

Ok this is probably simple but were missing something if it is, me and a friend have this select option to hide or show your email, but it sames our code isnt working, can anyone see anything wrong ?

 

 

       <?php

                if ($session->userinfo["show_email"] == true)
                $added = 'checked="checked"';

                else

                $added = '';

                echo "<input type = 'radio' name = 'show_email' value = '1' $added> Yes";

                if ($session->userinfo["show_email"] == false)

                $added = 'checked="checked"';

                else

                $added = '';

                echo "<input type = 'radio' name = 'show_email' value = '0' $added> No <br/>";

                ?>

 

Any help is appretiated.

Link to comment
Share on other sites

not working defined - when i click update profile it doesnt update the database, now i know 100% it isnt the rest of the code that updates the profile as i have several other options to update your profile that work in the exact same way, but they aredrop downs not radio buttons, this is my first time using radio buttons and i presumed everything was fine but during testing the code it isnt working, sorry if my explanation is a bit dull.

Link to comment
Share on other sites

The problem is that in HTML you would set it to CHECKED, not checked="checked"

 

Here's some cleaned up code:

 

<?php

               echo '<input type="radio" name="show_email" value="1"'.($session->userinfo["show_email"] == true ? ' checked ' : '').' /> Yes <input type="radio" name="show_email" value="1"'.($session->userinfo["show_email"] == false? ' checked ' : '').' /> No <br />';
?>

Link to comment
Share on other sites

JD your code isnt what i need, And Ken it isnt passing anything to the form that updates the database from hat i can gather, as i said i have other options that work in the exact same way just using drop down menu's so i know the Database updating form isnt broken, the only difference is the way the options are selected

Link to comment
Share on other sites

Ok this is another solid reason i beleive its the way the radio button form is broken, ive just used this as a test moethod to make the rest of my forms were working,

 

<tr><td>test:</td><td colspan="2"><textarea rows="4" cols="30" name="show_email">

<? echo $session->userinfo['show_email']; ?>

</textarea></td></tr>

 

and when i typed in 0 and hit update profile it worked, it updated my profile and hid my email address

Link to comment
Share on other sites

When i view the page source i see

<input type='radio' name='show_email' value='1' checked="checked"> Yes<input type='radio' name='show_email' value='0' > No <br/>

as i said this is my first time using radio buttons to select options, so it looks pretty normal to me

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.