I have a condition that executes and inserts my array into an SQLite database when a form is submitted. I require three of the same forms on other pages but with different column names and values that need to be inserted. I am not sure whether i should use the same form action 'post.php' on all of my forms and keep re-writing this block of code three times just with different table names, column names, and values:
$conn->exec("CREATE TABLE IF NOT EXISTS test (
firstName TEXT,
lastName TEXT,
Address TEXT)"
);
if (isset($_POST['input'])) {
$stmt = $dbh->prepare("INSERT INTO test (firstName, lastName, Address)
VALUES (:firstName, :lastName, :Address)");
$stmt->execute(array(':firstName' => $_POST['firstName'],
':lastName' => $_POST['lastName'],
':Address' => $_POST['Address']));
}
Or should i have a different PHP form action page for each of the different forms? Is it possible to insert this whole statement into a function and just change the column names and values somehow so i don't have to keep writing the same block of code over and over as its untidy and possibly bad practice? or would it be okay to execute three different create table statements and input conditions all in the same 'post.php file. I'm unsure whether this is bad practice or not, some advice would be greatly appreciated.
Aucun commentaire:
Enregistrer un commentaire