Before Insert Three data from radiobutton, I have to display some data from database. three radiobuttons and other display data is the same place (in a form), as follows:
<?php
$fetchdata = $db->prepare("SELECT * FROM input_voucher ORDER BY id");
$fetchdata->execute();
$getAllz = $fetchdata->fetchAll();
foreach ($getAllz as $rowz) {
$ch1=$rowz['price1'];
$ch2=$rowz['price2'];
$ch3=$rowz['price3'];
?>
<form action="" method="post" name="form">
<input name="var" id="voucher1" type="radio" value="1 Month">1 Month
<span>USD.<input type="text" name="txtprice1" id="txtprice1" value="<?php echo $ch1; ?>" readonly="readonly"></span>
<br />
<input name="var" id="voucher2" type="radio" value="2 Month">2 Month
<span>USD.<input type="text" name="txtprice2" id="txtprice2" value="<?php echo $ch2; ?>" readonly="readonly"></span>
<br />
<input name="var" id="voucher3" type="radio" value="3 Month">3 Month
<span>USD.<input type="text" name="txtprice3" id="txtprice3" value="<?php echo $ch3; ?>" readonly="readonly"></span>
<br />
<input type="submit" class="btn btn-primary" name="btnsubmit" id="btnsubmit" value="Contiue">
</form>
<?php
}
?>
Then, User must choose ONE CHOICE from the tree radiobuttons. When user check one of the buttons that means user also choose type of prices (price1,price2 or price3). The result from the choice picked is inserted into database, as follows:
UPDATED:
if (isset($_POST['btnsubmit'])){
$var= strip_tags($_POST['var']);
if ($var=='1 Month'){
$numprice=strip_tags(isset($_POST['txtprice1']));
}
elseif ($var=='2 Month'){
$numprice=strip_tags(isset($_POST['txtprice2']));
}
elseif ($var=='3 Month'){
$numprice=strip_tags(isset($_POST['txtprice3']));
}
//insert now
$mydata = $db->prepare("INSERT INTO voucher (colmonth,price) VALUES (:var,:numprice)");
$mydata->execute(array(':var'=>$var,':numprice'=>numprice));
echo "successfully saved!";
header('location:setup.php');
exit();
}
But it saved "1", not price. What does it mean? How to make it right price?