This is the form:
<form action="insert-product.php" method="POST">
<p>Product Title</p>
<input type="text" id="title" placeholder="Product title" name="p-title">
<p>Feature 1</p>
<input type="checkbox" id="feature-1" name="p-f1">
<p>Feature 2</p>
<input type="checkbox" id="feature-2" name="p-f2">
<p>Feature 3</p>
<input type="checkbox" id="feature-3" name="p-f3">
<input type="submit" value="Submit" id="submit">
</form>
This is the php code:
<?php
if(!empty($_POST) and $_POST['p-title']){
require 'connection.php';
$title = $_POST['p-title'];
$f1 = $_POST['p-f1'];
$f2 = $_POST['p-f2'];
$f3 = $_POST['p-f3'];
$prep = $db->prepare('INSERT into products(title, feature1, feature2, feature3) values(?, ?, ?, ?)');
if ($prep->execute([$title, $f1, $f2, $f3]))
echo "<h1 class=\"text-success\"> İşlem başarılı. Anasayfaya yönlendiriliyorsunuz. </h1>";
else
echo "<h1 class=\"text-danger\"> İşlem başarısız. </h1>";
}
?>
This is the result of when I check all the checkboxes:
And this is the result of when I do "not" check all the checkboxes:
I need it to be 0 when I do not check, and 1 when I do check. What is the solution for this situation?