is there a way to hand over a varying number of arguments to a function, which then inserts these arguments into a mysql-table?
the call would be something like:
insertNewRecord(‘name_of_field_1’, $content_to_write_1, ‘name_of_field_2’, $content_to_write_2);
and the function:
function insertNewRecord() {
$num_args = func_num_args();
$args = func_get_args();
for ($n = 0; $n <= $num_args; $n = $n + 2) {
$name_of_field = $args[$n];
$content_to_write = $args[$n+1];
mysql_query("INSERT INTO table_name ($name_of_field) VALUES ('$content_to_write')", connectionID)
or die ("Schreiben des Eintrags in die Datenbank nicht m?glich.");
}
}
what happens is, that the for-command, logically, creates a new entry into the database with every loop.
what i need, instead, is a code that gives the same result, as
mysql_query(“INSERT INTO table_name ($name_of_field_1, $name_of_field_2 … n) VALUES (’$content_to_write_1’, ‘$content_to_write_2’ … n)”, connectionID)
would do.
thank you very much in advance for any helpful idea.
cheers, andre