deeej Posted April 14, 2008 Share Posted April 14, 2008 Hi, Having real trouble for day's with this one, I am trying to upload a csv file to mySql dBase via a php script. I have a csv file and the contents of the file are as follows: Name|250|General|Asset|UK|AM|B1W2|www.website.com|Specialist|1 Name|250|General|Asset|UK|AM|B1W2|www.website.com|Specialist|1 Name|250|General|Asset|UK|AM|B1W2|www.website.com|Specialist|1 I have a mysql database set-up with exactly the same amount of columns to accept this data. Here is the PHP script I am using: if(isset($_POST['submit'])) { $filename=$_POST['filename']; $handle = fopen("$filename", "r"); while (($data = fgetcsv($handle, 1000, "|")) !== FALSE) { $import="INSERT into XXXXX(name,link,issue,date,type,type2,type2,type3,type4,typ45) values('$data[0]','$data[1]','$data[2]','$data[3]','$data[4]','$data[5]','$data[6]','$data[7]','$data[8]','$data[9]','$data[10]')"; mysql_query($import) or die(mysql_error()); } fclose($handle); print "Import done"; } else { print "<form action='converter.php' method='post'>"; print "Type file name to import:<br>"; print "<input type='file' name='filename' size='20'><br>"; print "<input type='submit' name='submit' value='submit'></form>"; } I Keep getting the same error: "Column count doesn't match value count at row 1". Much appreciate any1s help thanks!! Link to comment https://forums.phpfreaks.com/topic/101025-uploading-csv-to-mysql-via-php/ Share on other sites More sharing options...
deeej Posted April 14, 2008 Author Share Posted April 14, 2008 any1 have any idea? post got pushed on another page so no1 could see it Link to comment https://forums.phpfreaks.com/topic/101025-uploading-csv-to-mysql-via-php/#findComment-516794 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.