I would like to ask what is the efficient way to deal with these code. im checking changes in the form and if there are changes it store to DB. is there a way to convert 4 if statement into one. thanks
if ($_REQUEST['hidden_value_of_input_box1'] !== $newvalueofinputbox1) {
$data = "Input Box 1 has been changed";
$name = $name;
$date = $datenow;
$stm = $dbh->prepare("INSERT INTO audit SET name=:name, datenow=:datenow, data=:data");
$stm->bindParam(':name', $name); $stm->bindParam(':value', $value);
$stm->execute();
}
if ($_REQUEST['hidden_value_of_input_box2'] !== $newvalueofinputbox2) {
$data = "Input Box 2 has been changed";
$name = $name;
$date = $datenow;
$stm = $dbh->prepare("INSERT INTO audit SET name=:name, datenow=:datenow, data=:data");
$stm->bindParam(':name', $name); $stm->bindParam(':value', $value); $stm->execute();
}
if ($_REQUEST['hidden_value_of_dropdown1'] !== $newvalueofdropdown1) {
$data = "Drop Down 1 has been changed";
$name = $name;
$date = $datenow;
$stm = $dbh->prepare("INSERT INTO audit SET name=:name, datenow=:datenow, data=:data");
$stm->bindParam(':name', $name); $stm->bindParam(':value', $value); $stm->execute();
}
if ($_REQUEST['hidden_value_of_dropdown2'] !== $newvalueofdropdown2) {
$data = "Drop Down 2 has been changed";
$name = $name;
$date = $datenow;
$stm = $dbh->prepare("INSERT INTO audit SET name=:name, datenow=:datenow, data=:data");
$stm->bindParam(':name', $name);
$stm->bindParam(':value', $value);
$stm->execute();
}
on the form:
on the submition and processing:
something like that. 🙂