Forum Moderators: coopster
i want to create a function which adds any number of fields into the required table.
i have the following code, but it returns with an error.
function db_insert($table){
$query = "INSERT INTO ".$table." (";
$trigger = 0;
foreach($_POST as $field => $value){
if($trigger > 0) $query = $query . ", ";
$query = $query . $field;
$trigger++;
}
$query = $query . ") VALUES (trim('";
$trigger = 0;
foreach($_POST as $field => $value){
if($trigger > 0) $query = $query . ", trim('";
$query = $query . $value."')";
$trigger++;
}
$query = $query . ");";
if($result = mysql_query($query)) return(0);
else echo(mysql_error());
}
//END db_insert
The way I have submitted the form is with the following:
<input type="submit" name="submit" value="Submit" title="Submit" class="formButton" />
So the error is that it returns submit is not a column in the table, which it isn't.
How do i get around this?