Me: self taught, not a ton of exp with php or mysql
Situation:
Uploading CSV files to insert into pre-existing database tables using a web based interface.
Have placed into arrays all rows of CSV and can access individual elements
Have placed into variable database name from server
Have placed into variable database table selected from selected database
Have placed into an array field names for a given table.
All is dandy up until that point.
I am lost at the point of how to convert from the field name array into (field1, field2, ..., field"n") in the insert statement. How do I use an array to generate my field names in SQL friendly way?
Here is the code that works for the INSERT statement using a variable for the table name using a small table created for testing.
<?php
$query1=("INSERT INTO $dbtableselected (Shoes,Sandels,Socks) VALUES ('mud','crud','bud')");
mysql_query($query1) or die(mysql_error());
echo "data Inserted";
?>
How do I get from the $fieldnames array, which in this case holds
Array ( [0] => TesterTblId [1] => Shoes [2] => Sandels [3] => Socks )
to Shoes,Sandels,Socks so that it can be used dynamically to do the insert?