this is the very basic of what you need. You would of course put in the database update part within the while loop. Take out the ECHO statements as well unless you are debugging but basically with a little alteration this small piece of code will do what you need. if you need more info check out uk.php.net
You are missing the declaration of delimiters after the LOAD DATA INFILE in your SQL statement. You can use "FIELDS TERMINATED BY" and "LINES TERMINATED BY" to define these based on how your CSV file is delimited.
LOAD DATA LOCAL INFILE '/your_file.csv'
INTO TABLE your_table
FIELDS TERMINATED BY ','
LINES TERMINATED BY '\n'
(field1, filed2, field3);
noelthefish's suggestion in the previous post is a good one if you want to insert the CSV data programmatically. However, if it's just a one-time thing and you don't want to write a SQL statement, then the CSV import feature of PHPMyAdmin should do the trick.
you said you used phpmyadmin, i really becomes quite easy when phpmyadmin comes into picture. so you just nead to import the csv file using the import button and you are done.. suppose you have a "file.csv" file with format like this which you want to import 1,php,mysql 2,php,oracle 3,asp,mssql 4,java,oracle
so what you need to do in phpmyadmin interface is, 1. select a database 2. select a table where you want to import the csv file fields.. 3. click import button 4. browse for the file "file.csv" 5. change ';' to ',' as ';' is selected as default in the "Fields terminated by" field 6. click go and you are done.
This method works 100 % for me everytime, hope will for you too..
Start by exporting your data out of your excel spreadsheet! People are talking sometimes about importing the excel spreadsheet which is NOT a csv file (csv doesn't need to be comma delimited incidentally, tabs are quite acceptable)
so use Save as and select the file type of tab delimited text file, then use
LOAD DATA LOCAL INFILE '/your_file.txt' INTO TABLE your_table
I always use tab delimted rather than comma delimited because my data can have a comma in it and that caused problems the very first time I tried this (the data extract I was sent also had no '...' around the data - that might also have solved the problem I had, but I'm happy with tab delimited, so I stick with it). I've never had to specify the delimiter at all. I do this once every week to two tables, and it has worked okay for about four or five years now. I do have to give the full path to the file starting at c:...
I use HeidiSQL so I can connect to a remote database easily. One client is with a web host who does not include phpMyAdmin for "security reasons", which means I'd have to install it and set up any security it needs. Using a desktop application for remote access solves this as it by-passes the problem of a web page which might be found by others.