PHP CSV Upload to Database
Here is the simplest way I know of to take a CSV (comma separated value) file and upload it through a form, catch it with PHP and slam all the records into a database table. This should only be used "as is" in a controlled environment, as there is no input validation whatsoever, but it is enough to get the point across if you have never done this before.
PHP:
-
<?php
-
-
//CHECK THAT THE FILE WAS UPLOADED
-
-
//THIS WILL HELP IF ANY CSV FILES CREATED BY A MAC
-
-
//SPIN THROUGH THE RECORDS
-
-
//INSERT A RCORD TO THE DATABASE
-
mysql_query("INSERT INTO `table` (`field1`,`field2`,`field3`) VALUES ('{$data[0]}','{$data[1]}','{$data[2]}')");
-
-
}
-
-
}
-
-
?>
Home | PHP | PHP CSV Upload to Database
You’re currently reading “ PHP CSV Upload to Database ,” an entry on BRADINO
- Published:
- 5.29.07 / 5pm
- Category:
- PHP












