I am trying to create a function that takes an array of table fields and an array of values and inserts them into a mysql table. the function works if there is only one value in each array. If there is more than one value the values do not get inserted into the same row.
The code I have is as follows:
function insert_query($table, $field_array, $value_array) {
// connect to db
$conn = to_db();
$count = count($field_array)-1;
for($i=0; $i<=$count; $i++){
$insert = mysql_query("insert into $table($field_array[$i]) values('$value_array[$i]')")
so then I call the function like:
insert_query('friends', array(firstName, lastName), array(Gene, Barnett))
When I call it the first name value goes on a seperate value than the last name value. If I could get this to work that would be great. What would be optimal if I could get the whole array into the insert with out a for statement. Any help would be great.
Gomer Pyle