PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
I don't know how to set a check box as unchecked if they are already checked and then store the value as unchecked. When user uncheck a checkbox and click Submit it should become as unchecked and store into table value "no". But it doesn't, it allways shows as checked and it doesn't story value "no". Please tell me what I should do.
The code blow is just an example of how I store the value of yes if check box is checked.
thanks, I tried but still the same. Everytime the value posted via $_POST[] is the same if I leave checked or if I uncheck. I have no idea why the value is passed if I uncheck checkbox and click Submit.
That's very odd, when I run your code it sends the correct value via post. Perhaps it could be a browser thing, if you have any debugging plugins running you could try disabling them (I run firebug, and occassionally that causes some strange behaviour)
if (isset($_POST[Nick]) && $_POST[Nick]=='on')
{
mysql_query ("UPDATE users SET privacy='yes' WHERE uID='Nick'");
}
else
{
mysql_query ("UPDATE users SET privacy='no' WHERE uID='Nick'");
}
If I remember and I'm not wrong, when you use check boxes only when they are selected they are passed through the browser. So isset asks if the variable was created. I added $_POST[Nick]=='on' which I think it's extra but It's valid, since if the variable was passed it will contain the value "on" not "yes".