Uncheck check box if already checked
Posted: Sun Feb 01, 2009 8:20 am
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.
The code blow is just an example of how I store the value of yes if check box is checked.
Code: Select all
<?php
if ($_POST[Nick]=='yes')
{
mysql_query ("UPDATE users SET privacy='yes' WHERE uID='Nick'");
}
else
{
mysql_query ("UPDATE users SET privacy='no' WHERE uID='Nick'");
}
?>
<form action="<?=$_SERVER['PHP_SELF']?>" method="post">
<table>
<tr><td><input type='checkbox' name='Nick' value='yes'";
<?php
$result = mysql_query ("SELECT privacy FROM users WHERE uID = 'Nick'");
$row = mysql_fetch_assoc($result);
if ($row['privacy']=='yes')
{
echo "checked";
}
?>"></td></tr>;
<tr><td><input type="submit" value="Update"></td></tr>
</table>
</form>