I have a form with 25 fields that will have a value entered into each one and then written to MySQL. My insert statement is long and I don’t know what is a more effective way to right the insert statement without listing every field from the table and Post value. I would assume a loop.
foreach($_POST as $key => $value) {
$temp = is_array($value) ? $value : trim($value);
${$key} = $temp;
}
$resultQuery ="insert into canine_hemo (animal_id,test_type, hospital_id,vet_id,employee,test_date, white_blood_cell_count,seg_neutrophil_absolute,banded_neutrophil_absolute,lymphocyte_absolute,monocyte_absolute,eosinophil_absolute,basophil_absolute,other_absolute,blast_absolute,promyelocyte_absolute,myelocyte_absolute,metamyelocyte_absolute,red_blood_cell_count,hemoglobin,hematocrit,mcv,mch,mchc,platelet,segmented_neutrophils,banded_neutrophils,lymphocytes,monocytes,eosinophils,basophils)values('$animalName','canine_hemo','$hospital_ID','$vetID','$employeeName',NOW(),'$txt_White_Blood_Cell_Count','$txt_Seg_Neutrophil_Absolute','$txt_Banded_Neutrophil_Absolute','$txt_Lymphocyte_Absolute','$txt_Monocyte_Absolute','$txt_Eosinophil_Absolute','$txt_Basophil_Absolute','$txt_Other_Absolute','$txt_Blast_Absolute','$txt_Promyelocyte_Absolute','$txt_Myelocyte_Absolute','$txt_Metamyelocyte_Absolute','$txt_Red_Blood_Cell_Count','$txt_Hemoglobin','$txt_Hematocrit','$txt_MCV','$txt_MCH','$txt_MCHC','$txt_Platelet','$txt_Segmented_Neutrophils','$txt_Banded_Neutrophils','$txt_Lymphocytes','$txt_Monocytes','$txt_Eosinophils','$txt_Basophils')";
$result = $conn->query($resultQuery) or die(mysql_error());
}