Yohanne Posted September 11, 2013 Share Posted September 11, 2013 Hi coders, code below is working good and i confess that, this is not mine but when im trying to import big amount of file, let say 10MB upward. program was starting getting an error below but the data are successfully import. Notice: Undefined variable: data, line 13 Notice: Undefined offset: 30, line84 Notice: Undefined offset: 31, line85 Notice: Undefined offset: 32, line86 Notice: Undefined offset: 33, line87 Notice: Undefined offset: 34, line89 Notice: Undefined offset: 35, line90 Notice: Undefined offset: 36, line91 ... ... .... ... ... and when im importing small amount of data let say 4MB below the program is successfully redirect on this page import.php. if (isset($_FILES['csv']['size']) > 0) { $file = $_FILES['csv']['tmp_name']; $handle = fopen($file,"r"); do { if ($data[0]) { mysql_query("INSERT INTO stock( stock_id, Barcode, PLU, custom1, custom2, sales_prompt, inactive, allow_renaming, allow_fractions, package, tax_components, print_components, description, longdesc, cat1, cat2, goods_tax, cost, sales_tax, sell, quantity, layby_qty, salesorder_qty, date_created, track_serial, static_quantity, bonus, order_threshold, order_quantity, supplier_id, date_modified, freight, tare_weight, unitof_measure, weighted, external) VALUES ( '".addslashes($data[0])."', '".addslashes($data[1])."', '".addslashes($data[2])."', '".addslashes($data[3])."', '".addslashes($data[4])."', '".addslashes($data[5])."', '".addslashes($data[6])."', '".addslashes($data[7])."', '".addslashes($data[8])."', '".addslashes($data[9])."', '".addslashes($data[10])."', '".addslashes($data[11])."', '".addslashes($data[12])."', '".addslashes($data[13])."', '".addslashes($data[14])."', '".addslashes($data[15])."', '".addslashes($data[16])."', '".addslashes($data[17])."', '".addslashes($data[18])."', '".addslashes($data[19])."', '".addslashes($data[20])."', '".addslashes($data[21])."', '".addslashes($data[22])."', '".addslashes($data[23])."', '".addslashes($data[24])."', '".addslashes($data[25])."', '".addslashes($data[26])."', '".addslashes($data[27])."', '".addslashes($data[28])."', '".addslashes($data[29])."', '".addslashes($data[30])."', '".addslashes($data[31])."', '".addslashes($data[32])."', '".addslashes($data[33])."', '".addslashes($data[34])."', '".addslashes($data[35])."') "); } } while ($data = fgetcsv($handle,1000000,",",",")); header('Location:import.php'); } Quote Link to comment Share on other sites More sharing options...
jcbones Posted September 11, 2013 Share Posted September 11, 2013 The data cannot be correctly inserting, being that the data does NOT exist. That is what the notices are telling you. There will be gaps in the data, unless you add some de-bugging, you will not ever know what loop the notices are created on. You also are only asking for offsets 1 - 35, so I don't know where that "undefined offset 36" came from. *rambling on* You should also change this to a simple while loop, since the do section will never do anything on the first pass, until while is evaluated. In other words, you are creating the $data variable AFTER the first run of the loop, so there is no need to have a do/ while loop. Make it a simple while loop. You should also switch to the mysqli extension or PDO, and bind the parameters. That way you can type cast it correctly. I would also break up the inserts into chunks (multi row insert query), so I didn't have so many database calls. *rambling off* 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.