I have a checkbox input to insert activities into "act" colomn in "blooddonor" table in "sangamdb" database but I can't seem to figure out the right way to insert the multiple choices from my form to my database table. The other elements works fine except this one. My code so far: FORM:(I have other elements. I just mentioned the probleme)
<form role="form" action = "addeddonor.php" method = "post">
<div class="form-group">
<label for="exampleInputEmail1">Activites</label><br>
<input type="checkbox" id="Football" name="act[]" value="Football">
<label for="Football">FootBall</label><br>
<input type="checkbox" id="Basketball" name="act[]" value="Basketball">
<label for="Basketball">BasketBall</label><br>
<input type="checkbox" id="Nattation" name="act[]" value="Nattation">
<label for="Nattation">Nattation</label><br>
<input type="checkbox" id="Karate" name="act[]" value="Karate">
<label for="Karate">Karate</label><br>
</div>
</div>
<div class="box-footer">
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</form>
PHP:(It doesnt insert values into the database)
$checkBox = implode(',', $_POST['act']);
if(isset($_POST['submit']))
{
$query="INSERT INTO blooddonor (act) VALUES ('" . $checkBox . "')";
mysql_query($query) or die (mysql_error() );
echo "Complete";
}
if(isset($_POST['name'])){
$name = $_POST["name"];
$gender = $_POST["gender"];
$dob = $_POST["dob"];
$weight = $_POST["weight"];
$contact = $_POST["contact"];
$bloodtype = $_POST["bloodtype"];
$adress = $_POST["adress"];
include 'conn.php';
//code after connection is successfull
$qry = "insert into blooddonor(name,gender,dob,weight,contact,bloodtype,adress) values ('$name','$gender','$dob','$weight','$contact','$bloodtype','$adress')";
$result = mysqli_query($conn,$qry); //query executes
if(!$result){
echo"ERROR";
}else {
echo" <div style='text-align: center'><h1>ADDED SUCCESSFULLY</h1>";
echo" <a href='index.php' div style='text-align: center'><h3>Go Back</h3>";
}
}else{
echo"<h3>YOU ARE NOT AUTHORIZED TO REDIRECT THIS PAGE. GO BACK to <a href='index.php'> DASHBOARD </a></h3>";
}
DataBase:
CREATE TABLE IF NOT EXISTS `blooddonor` (
`id` int(11) NOT NULL,
`name` varchar(50) NOT NULL,
`gender` varchar(20) NOT NULL,
`dob` date NOT NULL,
`weight` int(5) NOT NULL,
`contact` int(10) NOT NULL,
`bloodtype` varchar(3) NOT NULL,
`adress` varchar(50) NOT NULL,
`act` varchar(50) NOT NULL
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=latin1;
Aucun commentaire:
Enregistrer un commentaire