stelthius Posted May 19, 2009 Share Posted May 19, 2009 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 More sharing options...
Ken2k7 Posted May 19, 2009 Share Posted May 19, 2009 You can't check a radio button, but you can select it. Get it? Link to comment https://forums.phpfreaks.com/topic/158792-php-radio-button-options-issue/#findComment-837486 Share on other sites More sharing options...
jackpf Posted May 19, 2009 Share Posted May 19, 2009 Yeah you can. Put this in a HTML file: <input type="radio" checked="checked" /> And define "not working"... Link to comment https://forums.phpfreaks.com/topic/158792-php-radio-button-options-issue/#findComment-837489 Share on other sites More sharing options...
stelthius Posted May 19, 2009 Author Share Posted May 19, 2009 sorry ken i think i missed your point? i think you meant were using checked rather than selected ? Link to comment https://forums.phpfreaks.com/topic/158792-php-radio-button-options-issue/#findComment-837492 Share on other sites More sharing options...
stelthius Posted May 19, 2009 Author Share Posted May 19, 2009 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 https://forums.phpfreaks.com/topic/158792-php-radio-button-options-issue/#findComment-837497 Share on other sites More sharing options...
Ken2k7 Posted May 19, 2009 Share Posted May 19, 2009 It was sarcasm. Sorry for that. Bad timing. Can you tell me the output of: var_dump($session->userinfo["show_email"]); Link to comment https://forums.phpfreaks.com/topic/158792-php-radio-button-options-issue/#findComment-837500 Share on other sites More sharing options...
stelthius Posted May 19, 2009 Author Share Posted May 19, 2009 Lol sorry ken been one of them long days XD the output of var_dump($session->userinfo["show_email"]); is string(1) "1" 1 = Show email 0 = hide email, thats how ive made it to be but i just cant get this radio selection to work, Link to comment https://forums.phpfreaks.com/topic/158792-php-radio-button-options-issue/#findComment-837503 Share on other sites More sharing options...
JD* Posted May 19, 2009 Share Posted May 19, 2009 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 https://forums.phpfreaks.com/topic/158792-php-radio-button-options-issue/#findComment-837504 Share on other sites More sharing options...
Ken2k7 Posted May 19, 2009 Share Posted May 19, 2009 JD*, xHTML disagrees - http://www.w3schools.com/Xhtml/xhtml_syntax.asp stelthius, what exactly isn't working? Link to comment https://forums.phpfreaks.com/topic/158792-php-radio-button-options-issue/#findComment-837507 Share on other sites More sharing options...
stelthius Posted May 19, 2009 Author Share Posted May 19, 2009 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 https://forums.phpfreaks.com/topic/158792-php-radio-button-options-issue/#findComment-837510 Share on other sites More sharing options...
stelthius Posted May 19, 2009 Author Share Posted May 19, 2009 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 https://forums.phpfreaks.com/topic/158792-php-radio-button-options-issue/#findComment-837515 Share on other sites More sharing options...
Ken2k7 Posted May 19, 2009 Share Posted May 19, 2009 Can you check the source code for the input radio buttons? Do they appear to be correct? Link to comment https://forums.phpfreaks.com/topic/158792-php-radio-button-options-issue/#findComment-837520 Share on other sites More sharing options...
stelthius Posted May 19, 2009 Author Share Posted May 19, 2009 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 https://forums.phpfreaks.com/topic/158792-php-radio-button-options-issue/#findComment-837524 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.