// the key is passed through the url with the name of the keyfield
list($tablekey, $keyvalue) = each($HTTP_GET_VARS);
//array for attaching the keynames to the corresponding tablenames
$tablearray=array();
$tablearray[arid]='artisttable';
$tablearray[clid]='clienttable';
$tablearray[cltid]='clienttypetable';
$tablearray[orid]='ordertable';
$tablearray[orlid]='orderlinestable';
//loop through the posted variables
//formfieldnames must be corresponding to tablefieldnames
//in case of array than arrayname must be corresponding fieldname
while ( list($field, $value) = each ($HTTP_POST_VARS)) {
if ($field <> "Submit" ){
if (is_array($value)){
$arrayLength = count($value);
$temparray=array_values($value);
for ($i = 0; $i < $arrayLength; $i++){
$temp=$temp .$temparray[$i] .";";
}
$fieldlines=$fieldlines .$field ."='" .$temp ."',";
}else{
$fieldlines=$fieldlines .$field ."='" .$value ."',";
}
}
}
$fieldlines=substr($fieldlines,0,strlen($fieldlines)-1); // get rid of the last ,
if (!empty($keyvalue)) //if no key in the url then consider it an insert statement
{
$query="UPDATE " . $tablearray[$tablekey] ." SET " . $fieldlines . " WHERE " . $tablekey ."='$keyvalue'";
}
else
{
$query="INSERT INTO " . $tablearray[$tablekey] . " SET ". $fieldlines;
}
$rs=mysql_query($query,$conn);