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
)
)
Material Issuing for receiving batch
Dear All experts in MM/ PP,
How To Make More Than One Redirection with PHP on the same page?
Hey im trying to do a direction page where it open differently link direction pages every time somebody enter it.. like this for example any good hint on how to do this?<?phpheader(
Simple image grab script.
I was wondering if it was possible and if anyone knew how to make a simple php script that looks at one specified directory and makes <img src="*.*" \> type links out of it?ive
PEAR Email Attachment w/ $gpg
I have no issues with this code if I take out the attachement section and include the info in the email body instead. However, I want the info to be in an email attachment. I do receive the email,
problem with array - multilingual page
this is my test page :Code: <?php if(isset($_GET['lang'])) { if($_GET['lang'] == "en") { require_once("languages/lang-en.php"); }
Problem in back link
I have page where i have given javascript back link but when i click on it browser give a messageWebpage has expired
MySQL issue
I am taking sentences through a form on page. Then checking some condition and trying to insert them in database. I have issues while inserting...foreach ($sentences as $final) {......else {
How to create a static html menu from a database
Hi,I have built a small cms which allows me to create simple html pages and then upload them to an ftp.Everything is working apart from the menu, I cant get my head round how to create the menu
Php - mysql store data and use it later?
Hi, i' making a login page at the moment, however my username + password is stored many different places, and is kinda hard to get, so I have written this entire code:Code:
Need help: how to catch acess of undefined class properties
Hello. I am learning OO with PHP and have hit a problem.Some code runs as perfectly valid code, where i would like PHP to issue a warning / error.I guess this is because of the loose typing of PHP,