Hi, I've got a form with 4 text inputs and 79 option select boxes. Is there an easier way to build the sql insert other than listing all 83 db fields and all 83 form fields (although not all form fields are likely to have data it is still important to have the empty value if no data is selected)?
I've tried several ways of writing the INSERT command with leaving out the column names , eg. (), and trying to use the global $_POST as the VALUES, but nothing seems to work.
I only have to write this INSERT once so its no big deal if that is the way to handle, but it seems that programatically there should be a "neater" way of writing it than having a HUGE insert statement.
My code for this function is (simplified to show only the first 4 fields for test purposes):
function add_data($newname, $haplogroup, $kitnum, $subgroup) {
// Add new DNA to the database
$conn = db_connect();
// check not a duplicate kit
$result = $conn->query("select * from DNAresults
where kitnum='$kitnum'");
if ($result && ($result->num_rows>0)) {
throw new Exception('This kit is already in the database.');
}
// insert new results
if (!$conn->query("insert into DNAresults
(descendant, haplogroup, kitnum, fam_group)
values ('".$newname."', '".$haplogroup."', '".$kitnum."', '".$subgroup."')")) {
throw new Exception('Data could not be inserted.');
}
return true;
}