ash992 Posted May 20, 2014 Share Posted May 20, 2014 hey guys, I'm getting a problem uploading my csv file to mysql database, the code on the top half just makes sure that I don't import data that I don't want into the database, numbers that are too high or too low on certain rows, and the second half is importing the array that I create from the csv file into the database however I'm getting the following error Duplicate entry 'Array' for key 'strProductCode' Now I've never had this error before and I'm not sure what's causing it so any help would be very much appreciated $data = array(); if (($handle = fopen("stock.csv", "r")) !== FALSE) { while (($row = fgetcsv($handle, 1000, ",")) !== FALSE) { // only add rows to the array where the 4th column value is greater than or equal to 10 if(($row[3] >= 10 && $row[4] >= 5) OR ($row[3] >= 0 AND $row[4] > 5)){ if($row[4] < 1000){ $data[] = $row; } } } foreach ($data as &$value) { mysql_query("INSERT INTO tblProductData (intProductDataId, strProductCode, strProductName, strProductDesc, strProductStock, strProductCost, dtmDiscontinued, dtmAdded, stmTimestamp) VALUES(null, '$data[0]', '$data[1]', '$data[2]', '$data[3]', '$data[4]', 'time', 'added', 'time') ") or die(mysql_error()); } } Thanks in advance guys! if you have any clue at all I'd love to hear it. Quote Link to comment Share on other sites More sharing options...
ash992 Posted May 20, 2014 Author Share Posted May 20, 2014 oh btw, I've just taken a look in the database and this is what is imported when I run the script so possibly the reason for it saying there's a duplicate is becuase I'm uploading the array incorrectly? so it's just trying to upload the wrong values everytime to the same row? :S if you know anything about this it would be great, thanks again in advance! Quote Link to comment Share on other sites More sharing options...
Solution Jacques1 Posted May 20, 2014 Solution Share Posted May 20, 2014 I think $data[0] etc. should actually be $value[0] etc. $data is your entire array of rows, $value is the current row. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.