Jump to content

Checkbox updating database


cronThis

Recommended Posts

<?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>

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.