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
https://forums.phpfreaks.com/topic/158792-php-radio-button-options-issue/
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.

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 />';
?>

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.