I'm using prepared statement to insert into mysql , the inserted value should be either 0 or 1 but in the database it's either null or 1
in the create table I made sure to specify the default to be 0 and it works well on phpMyAdmin but using php to insert from form makes it either null or 1
CREATE TABLE taby (v1 INT(1) DEFAULT '0',v2 INT(1) DEFAULT '0',v3 INT(1) DEFAULT '0')
my php file
if(isset($_POST['submit']))
{
$stamt = $conn->prepare("INSERT INTO taby (v1, v2,v3) VALUES (?,?,?)");
$stamt->bind_param("iii", $_POST['v1'], $_POST['v2'],$_POST['v3'] );
$stamt->execute();
}
?>
<form action="#" method="post" >
<input type="checkbox" name="v1" class="checkbox" value="0">
<input type="checkbox" name="v2" class="checkbox" value="0">
<input type="checkbox" name="v3" class="checkbox" value="0">
<button type="submit" name=submit> SUBMIT</button>
</form>
I did try in the create table statement to make them all NOT NULL but no error appeared and no value was inserted unless all the checkboxes were marked
I have a jquery script to toggle the value from 0 to 1