rafal Posted September 25, 2014 Share Posted September 25, 2014 (edited) hallo everybody, i have column in my guestbook table mysql database names vis. i want make it possible for user to make theier comments invisible. if user checked yes, the comment will be viewd. if he did not checked, the comment will not be viewed. in my visibility.php the user can later change the value from yes to no or from no to yes. i do not know how to make this possible in update.php file. thank you very much for your help. Rafal here is my code which not work in visibility.php <form action="update.php" method="post"> <input type="hidden" name="inp_id" value="<?php echo $row[id) ?>"> visible: <input type="checkbox" name="inp_vis" <?php if ($row[vis] == "yes") { echo "value='yes' checked"; } else { echo "value='no'"; } ?>> <br> <input type="submit" value="Save"> </form> Edited September 25, 2014 by rafal Quote Link to comment Share on other sites More sharing options...
CroNiX Posted September 25, 2014 Share Posted September 25, 2014 Checkboxes will only be transmitted if they are actually checked, so just check to see if it isset(). $checked = isset($_POST['inp_vis']); Quote Link to comment Share on other sites More sharing options...
Psycho Posted September 25, 2014 Share Posted September 25, 2014 As to your code, you do not change the value of the checkbox. And, in this case the value really isn't important. The checkbox should use the same value and you should check/uncheck it based upon the saved data. Also, you should save the value as a numeric equivalent of a Boolean, i.e. 0 (false) or 1 (true). visible: <input type="checkbox" name="inp_vis" value="visible" <?php echo if ($row['vis']) "checked='checked'"; ?>> 1 Quote Link to comment Share on other sites More sharing options...
rafal Posted September 25, 2014 Author Share Posted September 25, 2014 Thank you dear CroNiX. dear Psycho, Thank you, i entered your code but i got this error: Parse error: syntax error, unexpected 'if' (T_IF) in update.php on line 92 Quote Link to comment Share on other sites More sharing options...
Solution rafal Posted September 26, 2014 Author Solution Share Posted September 26, 2014 thank you all, problem solved 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.