surge42 Posted March 11, 2013 Share Posted March 11, 2013 Guys, I'm a newbie. There, I got that out of the way.... I have a form that can be submitted and then modified. The data gets sent to a mySQL db. It's nothing special. The idea is that the user is to click a checkbox located at the bottom of the form that says "I'm finished with my project" when checked the stored value is "yes". Everything works fine the value gets stored and all is well except I can not get the darn thing to echo the chekced value. Below is what I have tried with no joy. <input type="checkbox" name="projectcomplete[]" <?php if ($user_type_detail["projectcomplete"]=='Yes') {echo "checked";} ?>> Why the heck won't it work? The value "yes" is stored. Arrrggggg.... I also tried isset with no joy... <input type="checkbox" name="projectcomplete" <?php if (isset($yes)) { echo 'value="checked"'; }?> > The following code below works perfectly on the form. I have refferenced it but no solution materialized. What can I tell ya.. I'm a newb... I don't have the skills to uncover the solution. input type="radio" class="radio" name="CYSD_Particiapant" value="Yes" <?php if($user_type_detail["CYSD_Particiapant"]=='Yes') echo 'checked=checked';else echo '';?> />Yes<input class="radio" type="radio" name="CYSD_Particiapant" value="No" <?php if($user_type_detail["CYSD_Particiapant"]=='No') echo 'checked=checked';else echo '';?> />No Any help would be very much appriated. Quote Link to comment Share on other sites More sharing options...
Psycho Posted March 11, 2013 Share Posted March 11, 2013 OK, let's take one step at a time. <input type="checkbox" name="projectcomplete[]" <?php if ($user_type_detail["projectcomplete"]=='Yes') {echo "checked";} ?>> Why the heck won't it work? The value "yes" is stored. Arrrggggg.... OK, how do you know it is stored? Have you verified the value through PHPMyAdmin? Have you echo'ed $user_type_detail["projectcomplete"] to the page to verify it's contents? have you verified that the field name is correct (you state the last example works but it has a typo in the field name)? Are you sure the value is exactly "Yes" and not "yes" or "YES"? Don't assume what variables contain because you think you know what they should contain. Test Them! Echo them to the page or write some code to test them. That is the basics of debugging. Also, I would highly suggest NOT using "Yes" or "No" for a field value. instead make the field an INT and store 0/1 which can be logically interpreted as TRUE and FALSE. Then you don't nee to worry about putting a typo in your comparisons such as if($var == 'Yes') Instead you can test the variable directly if($var) which will be true is $var is a 1 and false if $var is 0 Quote Link to comment Share on other sites More sharing options...
davidannis Posted March 12, 2013 Share Posted March 12, 2013 In your third (working example) you have no square brackets after the variable name - it is a variable not an array (which is what you want) and you use checked=checked which will work. In example 2 you use value=checked -- won't do what you want In example 1 you echo just checked (which will work but is deprecated) but have [ ] after the variable name making it an array and I suspect you don't process it as an array. Quote Link to comment Share on other sites More sharing options...
davidannis Posted March 12, 2013 Share Posted March 12, 2013 if you need to see what your variables look like try using print_r($_POST); or print_r($_GET); Quote Link to comment Share on other sites More sharing options...
surge42 Posted March 12, 2013 Author Share Posted March 12, 2013 Thanks folks all great points.. I will test when have half a brain left. Much thanks... Quote Link to comment Share on other sites More sharing options...
surge42 Posted March 12, 2013 Author Share Posted March 12, 2013 Thanks fellas! Got it working... Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.