Reputation: 111
I am creating an HTML form and I have a textbox in that. My requirement is that a user can check multiple check boxes, and then I have to get all checked values and then send the values to the database (I want to use PHP).
Here is my code for within the textbox
$Intensive=$_POST['Intensive'];
$Intensive_count=count($Intensive);
$i=0;
//$count=0;
//$index;
$max=0;
//$index;
While($i < $Intensive_count)
{
if($Intensive[$i]=="High frequency ventilation" )
{
$Intensive_score=4;
}
elseif($Intensive[$i]=="Mechanical ventilation with muscle relaxation")
{
$Intensive_score=4;
}
elseif($Intensive[$i]=="Mechanical ventilation")
{
$Intensive_score=3;
}
elseif($Intensive[$i]=="CPAP")
{
$Intensive_score=2;
}
elseif($Intensive[$i]=="supplemental oxygen")
{
$Intensive_score=1;
}
if($Intensive_score>$max)
{
$max=$Intensive_score;
$index=$i;
}
$i++;
}
Now with the above code I am able to echo the value ,but the record is not going to the database.
$sql1="insert into Form2 values('$Medical_Record_Id','$sub1','$Question1','4','$Intensive[$index]','$max')";
mysql_query($sql1);
Could anybody tell me how to go about it.
Thanks ..:)
Upvotes: 0
Views: 169
Reputation: 43810
I would recommend you use integers for the value instead of long strings, also an ID is supposed to be unique, so modify your ids.
HTML:
<input type="checkbox" name="Intensive[]" id="r1" value="1">supplemental oxygen<br>
<input type="checkbox" name="Intensive[]" id ="r2" value="2">supplemental oxygen<br>
<input type="checkbox" name="Intensive[]" id="r3" value="3">Mechanical ventilation<br>
<input type="checkbox" name="Intensive[]" id="r4" value="4">Mechanical ventilation with muscle relaxation<br>
<input type="checkbox" name="Intensive[]" id="r5" value="5">High-frequency ventilation
PHP:
foreach($_POST['Intensive'] as $data) {// Or $_GET
if ($data == 1){
/// do so and so
}
if ($data == 2){
/// do so and so
}
... and so on.
}
Upvotes: 0
Reputation: 76240
Assuming you are using POST
as the method for sending the form those checkboxes are in, you can get the values array with $_POST['Intensive']
.
Upvotes: 1