I have a problem with a piece of code I wrote to import some records from a csv file into mysql. I have a .csv file with about 300 records in it. The code worked perfect while testing on 3 or 4 records. When I tried to import the entire list I ran into problems where there were gaps of records that had no data.
I tested some of the records that were being missed thinking that it was a charachter in the record making sql choke, but when I did blocks of 5 or 10 of the bad records they worked. This is the error message:
Warning: array_combine() [function.array-combine]: Both parameters should have an equal number of elements in
At some point the insert starts inserting records again and then it hits another block of errors. I am thinking this has to do with some kind of memory limit but the csv file is only 66kb.
Any ideas?
Here is the code
Code: [Select]$handle = fopen($_FILES['filename']['tmp_name'], "r");
if ($handle)
{
set_time_limit(0);
//the top line is the field names
$fields = fgetcsv($handle, 4096, ',');
//loop through one row at a time
while (($data = fgetcsv($handle, 4096, ',')) !== FALSE)
{
$data = array_combine($fields, $data);
// Create a Joomla Password and insert the un-encrypted and encryted+salt value into array
$password = generatePassword($length=9, $strength=4);
$data[password] = $password ;
require_once 'libraries/joomla/user/helper.php'; //Use Joomla function in order to salt the password and encrypt
$salt = JUserHelper::genRandomPassword(32);
$crypt = JUserHelper::getCryptedPassword($password, $salt);
$md5password = $crypt . ':' . $salt;
$data[md5password] = $md5password;
// Insert Customer info into jos_user table
$jos_users = sprintf("INSERT into jos_users_test(name,username,email,password,usertype,sendEmail,gid,registerDate) values('%s','%s','%s','%s','%s','%d','%d',NOW())",
sql_prep($data[Contact], $db),
sql_prep($data[Customer], $db),
$data[Email],
$data[md5password],
'Registered',
'1',
'18');
mysql_query($jos_users) or die(mysql_error());
Here is the output of the array, you can tell [15] doesn't have any of the data that [14]and all the rest have. Then it will pick up at some point and a bunch will have data and then it will choke again.
[14] => Array
(
[Customer] => XXXXXXXXX
[Contact] =>
[Phone] => XXXXXXXXXXXX
[Fax] =>
[Alt. Phone] =>
[Alt. Contact] =>
=> [email]tXXXXXX@yahoo.com
[Bill to 1] => XXXXX
[Bill to 2] => XXXXXXXXX
[Bill to 3] => XXXXXXXX
[Bill to 4] =>
[Bill to 5] =>
[Ship to 1] => XXXXXXX
[Ship to 2] => XXXXXXXXX
[Ship to 3] => XXXXXXXX
[Ship to 4] =>
[Ship to 5] =>
[password] => password
[md5password] => 461543387f04a4848d38a6d6fd7376cc:0GHs3PRXbdsqbeghoiZnKxJeudwAYtv3
)
[15] => Array
(
[password] => password
[md5password] => d2db7721b7df8f151ef342a3a72aa32d:bwGLFCJnCdDTjDZH2b5kqfIL5QJ3z42h
)
)
want a code for uploading and downloading
i m trying to upload and download to my site..i need upload and download code ...i use a code for upload but that is not working actually..i don't know what is the problem.when i upload a file and
Is there a function ... auto send IP
Is there some function that can be sent to a ddns service that returns the ip address of a ddns forward. I am working on a script that uses a dvr from a home and the owner wants to have the dvr stream
check if value exists
I have googled this for a while and I am getting lots of different results. Is there a standard method used for checking to see if a value exists in a database before inserting a value? I have a form,
is this the proper use of mysql_real_escape_string() to prevent sql injections?
i was wondering is this the proper use of mysql_real_escape_string() to prevent sql injections? any help greatly appreciated. thanks. derekCode:
search function
HI guys,if anyone could point us in the right direction of how to do this, or provide some test code for a similar problem would be great!Basically, I have user profiles on my site, and I have a
Count number of records in all the tables with a querry URGENT PLEASE...
I downloaded ORACLE 9I DATA DUMP into my comp. There are number of tables. I need to find out the tables with records more than say 100 or so at on go. Can it be possible... If so kindly let me
formating when pulling data from a mysql databaseOk so Im not to sure if this is the right thread to post in but here is my catch 22 issue.I have a test web page www.aandstech.com.au/test.phpTest.php pulls its content from a my sql table.This works
pointer 102 question
I read a book
New Search Engine
Hey everyone,I have a ZIP Code Radius search engine already functional. it displays all of the ZIP codes within a specified mileage around a central ZIP code.I have an auction site that the client
problem with script manager
Hi iam using Net.2005.I have created ajax enabledwebsite.i have master page in which i have script manager.Ihavedifferent page in which iam trying to use ajax extension likeupdatepanel and update