here is my code i want that what ever value is checked that value is inserted into database
i have created database with name doctor table name diseases with 3 field id dis_name and Ans
plz help its urgent
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
require 'db.php';
if ( !empty($_POST)) {
// keep track validation errors
$disError = null;
$ansError = null;
// keep track post values
$dis_name = $_POST['name'];
$ans=isset($_POST['ans']);
// validate input
$valid = true;
if (empty($dis_name)) {
$disError = 'Please enter Diseases Name';
$valid = false;
}
if (empty($ans)) {
$ansError = 'Please check one of option';
$valid = false;
}
// insert data
if ($valid) {
$pdo = Database::connect();
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql = "INSERT INTO diseases (dis_name,Ans) values(?,?)";
$q = $pdo->prepare($sql);
$q->execute(array($dis_name,$ans));
Database::disconnect();
//header("location: diseases.php");
}
}
?>
// some html code
<div class="control-group <?php echo !empty($ansError)?'error':'';?>">
<label class="check">Have you suffered pain preiviously:</label>
<div class="controls">
<input type="radio" name="choice[]"<?php if (isset($ans) && $ans=="Yes") echo "checked";?>
value="Yes">Yes
<input type="radio" name="choice[]"<?php if (isset($ans) && $ans=="No") echo "checked";?>
value="No">No
<?php include 'loaded.php'; ?>
</div>
</div>
// loaded.php
<?php
if(isset($_POST['submit'])){
if(!empty($_POST['choice[]'])) {
// Counting number of checked checkboxes.
$checked_count = count($_POST['choice[]']);
echo "You have selected following ".$checked_count." option(s): <br/>";
// Loop to store and display values of individual checked checkbox.
foreach($_POST['choice[]'] as $selected) {
echo "<p>".$selected ."</p>";
$qry="insert into diseases (Ans) values ($selected)";
}
echo "<br/><b>Note :</b> <span>Similarily, You Can Also Perform CRUD Operations using These Selected Values.</span>";
}
else{
echo "<b>Please Select Atleast One Option.</b>";
}
}
?>