I would like to have a submit code that works with different forms like:
<?php
$type = $_GET['type'];
if(isset($_SESSION['id']))
handle_form();
else
include 'form_'.$type.'.php'; // different fields based upon type
?>
So I was wondering if it was wise to loop through superglobal $_POST writing all keys and values to the database. Something like:
<?php
function handle_form() {
$query = "";
foreach($_POST as $key => $value) {
$query .= mysql_real_escape_string($key)."='".mysql_real_escape_string($value)."' AND ";
}
mysql_query("UPDATE ".$_POST['type']." SET ".substr($query,0,-4)."WHERE `id` = $_SESSION['id']");
}
?>
Or is this a very insecure approach for handling forms and is it better to hardcode all fields in the corresponding 'form_type.php'?