Hi I have an insert and an update statement. The update works fine, I have two fields, one category_of_taxom and number_of_taxom. The update allows either one to be changed and it will update the record.
However the insert which is pretty much the same, if it is not already existing creates the record. Will work if I input values for both options, but if only one is inputted it does not submit anything? The code is quite complicated, with all the variable names, but Im thinking I maybe need another if statement or something? to check if just one is inputted? or is this a PDO thing that all parameters need filling?
$stmt6 = $conn ->prepare("UPDATE record_tbl SET category_of_taxom =?, number_of_taxom =? WHERE sheet_id = ? AND line = 6");
$stmt6->bindParam(1, $category_of_taxom66);
$stmt6->bindParam(2, $number_of_taxom66);
$stmt6->bindParam(3, $sheet_id);
$category_of_taxom66 = $_POST['categorySelect6fromDB'];
$number_of_taxom66 = $_POST['number_of_taxom6'];
$stmt6->execute();
echo "Saved!";
}
else
{
if (isset($_POST['categorySelect6fromDB'])) {
$category_of_taxom66 = $_POST['categorySelect6fromDB'];
$param_cat = PDO::PARAM_INT;
}
else {
$category_of_taxom66 = NULL;
$param_cat = PDO::PARAM_NULL;
}
if (isset($_POST['number_of_taxom6'])) {
$number_of_taxom66 = $_POST['number_of_taxom6'];
$param_num = PDO::PARAM_INT;
}
else {
$number_of_taxom66 = NULL;
$param_num = PDO::PARAM_NULL;
}
$stmt66 = $conn ->prepare("INSERT INTO record_tbl (line, taxom_id, category_of_taxom, number_of_taxom, sheet_id) VALUES (6,6,?,?,?)");
$stmt66->bindParam(1, $category_of_taxom66, $param_cat);
$stmt66->bindParam(2, $number_of_taxom66, $param_num);
$stmt66->bindParam(3, $sheet_id);
$stmt66->execute();
echo "New Record Inserted!";
}
}