cronThis Posted February 8, 2008 Share Posted February 8, 2008 How can I get a checkbox form to change a value in a table? For example, I just want a value changed from a 0 to a 1 based on whether someone checked off if something has been accepted of unaccepted. Quote Link to comment https://forums.phpfreaks.com/topic/90066-checkbox-updating-database/ Share on other sites More sharing options...
pocobueno1388 Posted February 8, 2008 Share Posted February 8, 2008 <?php if (isset($_POST['check'])){ //The checkbox was checked, update the database $query = mysql_query("UPDATE table SET field=1 WHERE fieldID='$some_var'")or die(mysql_error()); } ?> <form> <input type="checkbox" name="check"> <input type="submit" name="submit"> </form> Quote Link to comment https://forums.phpfreaks.com/topic/90066-checkbox-updating-database/#findComment-461806 Share on other sites More sharing options...
unidox Posted February 8, 2008 Share Posted February 8, 2008 Here: <? if ($_POST) { $name = $_POST['name']; if ($name != 0) { $name = 1; else { $name = 0; } } else { ?> <form action="#" method="POST"> <input name="name" type="checkbox"> <input type="submit"> </form> <? } ?> Then just add you query to inset/update Quote Link to comment https://forums.phpfreaks.com/topic/90066-checkbox-updating-database/#findComment-461808 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.