lundi 17 mai 2021

Insert value of multiple checkbox in sqlite database using php pdo

Hi I have multiple check boxes name make and female I want that if a person select make and don't select female it input nothing or false in database now if I don't select example: female it return nothing in female row but it also get a error

Undefined index: Female in /storage/sdcard1/www/3/signup/index.php on line 11

but I don't want this error and I want the if female not select it insert false and don't show error I don't want the selected check box value to be true because it is wrote as on in database Pls don't down vote I really want help of you guys Code index.php

<?php 
if(isset($_POST['submit'])){
    
$conn = new PDO("sqlite: sign.db");
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    $Email = $_POST['Email'];
    $First = $_POST['First'];
    $Last = $_POST['Last'];
    $Password = $_POST['Password'];
    $Male = $_POST['Male'];
    $Female =$_POST['Female'];
     $Dateofb = $_POST['Dateofb'];
  require_once 'imp.php';
    
}
?>
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="index.css"  >
<script src="index.js" ></script>
<title>Survey</title>
</head>
<body>
<form action="" method="post"  >
<div class="container" >
<div class="form" >

<input type="email" class="first"  id="Email" name="Email" placeholder="Email" required="required">
<input type="text" class="second"  id="First" name="First" placeholder="First name" required="required">
<input type="text" class="last"  id="Last" name="Last" placeholder="Last name" required="required">
<input type="password" class="pass" name="Password" id="Password" placeholder="Password" required="required">

<div class="day" >

<p class="bd" >Birthday Date:</p>

<input type="date" class="date" id="Dateofb" name="Dateofb" >

</div>
<div>
<div class="malee" >
<input type="checkbox" class="male" id="Male" name="Male">
<p class="mal" >Male</p>
</div>
<div class="femalee" >
<input type="checkbox" class="female" id="Female" name="Female" >
<p class="fem" >Female</p>
</div>
</div>
<div >
<input class="submit" id="submit" type="submit" name="submit"  >
</div>
<div class="acc" >
already have account <a href="#" >Login</a>
</div></div>
</div>
</form>
</body>
</html>
        

Code imp.php

<?php

    
$sql = "INSERT INTO signup (`Email`, `First`, `Last`, `Password`, `Male`, `Female`, `Dateofb`) VALUES ('$Email', '$First', '$Last', '$Password', '$Male', '$Female', '$Dateofb');";
 
    // use exec() because no results are returned
    $conn->exec($sql);
    echo "New record created successfully";
    $conn->connection = null;
?>



Aucun commentaire:

Enregistrer un commentaire