Arrays, Variables, and SQL
Posted: Wed Feb 19, 2003 7:32 pm
I have 2 elements - the first, a variable ($sql), will become an SQL statment to insert into a database, the other ($formarray) is an array where $key= the names of a form, as well as the fields in the database, and $value= the values of said form elements. Using foreach I want to populate $sql with an Insert Set statment, but I need to specify the opening phrase of the SQL statement ("INSERT INTO table_n SET ") without repeating it each time.
Here's what I have:
I want to put the output of that into the middle of an SQL statement. Also I don't want the last line to include a comma at the end, or the SQL won't work.
Any ideas?
Here's what I have:
Code: Select all
<?php
foreach ($formarray as $key => $value) {
$output = "$key = '$value',";
echo $output;
}
?>Any ideas?