News:

Wondering if this will always be free?  See why free is better.

Main Menu

Importing member database with CSV file

Started by unafraid, January 12, 2011, 03:28:36 AM

Previous topic - Next topic

unafraid

I've been struggling for days trying to import a database of 263 members from a CSV file.

I tried using H's csvimport.php file here:

http://www.simplemachines.org/community/index.php?topic=211606.new#new
(His post from Dec 18th, 2007)

I put both that and the members.csv file in the root directory of the forum, and put domain/csvimport.php in Firefox, but it said 'please give valid email address' for the first entry. Tried changing the email address to one that I know works, but got the same result. Tried exchanging the email and password columns in the .csv file, but same result.

The csvimport.php says:

//This array is shamelessly copied from ManageRegistration.php =D
         $regOptions = array(
         'interface' => 'csvimport',
         'username' => $key[0],
         'email' => $key[2],
         'password' => $key[1],
         'password_check' => $key[1],
         'check_reserved_name' => true,
         'check_password_strength' => false,
         'check_email_ban' => false,
         'send_welcome_email' => false,
         'require' => 'nothing',
         'memberGroup' => 0,

so in theory it looks like it should be column A Username B Email address C Password.
That's all I have in the file, separated by commas, one to each line, with no headings on the columns, just the names/email addresses/unencrypted passwords.

Where am I going wrong, please?

DavidCT

Me personally, I would have replied to that thread instead of making a new one (sometimes you shouldn't, but for this I would have)

Anyway, the order appears wrong...


'username' => $key[0],
'email' => $key[2],
'password' => $key[1],
'password_check' => $key[1],


username, password, email

Either redo your CSV, or easier - change 1 to 2 (both) and 2 to 1


'username' => $key[0],
'email' => $key[1],
'password' => $key[2],
'password_check' => $key[2],

unafraid

David, thanks very much for your help.
Just returned home exhausted from jury duty followed by work,
so will get on to it tomorrow.

Re starting a new topic, I originally restarted the old thread on the same topic,
but was told to take my problem elsewhere, and so I put a post on scripting help,
and then was told it was the wrong place and to try here.


unafraid

Okay, have edited the import.php file to reflect the suggestions you've made so it now reads:

<?php
//Open the template
$csv = fopen("members.csv", "r") or die("CSV file members.csv could not be found");

$csvdata = array();

while (($temp = fgetcsv($csv, 1000, ",")) !== FALSE) {
   
   $csvdata[] = $temp;
   
}
unset($temp);

//Include SSI.php
require("SSI.php");

//include Subs-Members.php
require("Sources/Subs-Members.php");

foreach($csvdata as $key)
{
   echo 'Importing user: ', $key[0] ,'...</br>';
      //This array is shamelessly copied from ManageRegistration.php =D
         $regOptions = array(
         'interface' => 'csvimport',
         'username' => $key[0],
         'email' => $key[1],
         'password' => $key[2],
         'password_check' => $key[2],
         'check_reserved_name' => true,
         'check_password_strength' => false,
         'check_email_ban' => false,
         'send_welcome_email' => false,
         'require' => 'nothing',
         'memberGroup' => 0,
      );
   $memberID = registermember($regOptions);
      if(!empty($memberID))
      {
         echo 'Done. <a href=index.php?action=profile;u=', $memberID ,'>Member Profile</a><br />';
      }
      else
      die("Error importing member");
}         

echo 'Import complete';
?>


I dropped both the import.php and the members.csv in the root directory of my forum.

When I input www.mydomain/import.php in my browser I got the message:


Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /home/content/j/a/c/mydomain/html/import.php on line 9

Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /home/content/j/a/c/mydomain/html/import.php on line 10

Parse error: syntax error, unexpected T_VARIABLE in /home/content/j/a/c/mydomain/html/import.php on line 11



I can't see any '\' characters in the code. I created a simple csv file with just 3 usernames, emails and passwords in that order.

DavidCT

Missing a { after else and } after die line to end IF

   if(!empty($memberID))
   {
      echo 'Done. <a href="index.php?action=profile;u=', $memberID ,'">Member Profile</a><br />';
   }
   else
   {
      die("Error importing member");
   }
}
(this bottom one is already there)

I also added the needed " quotes for the hyperlink.

Without trying it that's all I see.  Sometimes some errors cause other weird errors, so this might fix it.

unafraid

Thanks so much.
Will try it and report back.

I'm sure there are many people this would be useful for.

unafraid

#6
I tried the suggested changes, and got the response:

Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /home/content/j/a/c/username/html/csvimport.php on line 8

Parse error: syntax error, unexpected T_VARIABLE in /home/content/j/a/c/username/html/csvimport.php on line 10

so I'm going to give up and doing it manually as I can't wait any longer. It will take me a few hours but at least I'll be able to see the result and I know it'll work.
Thanks anyway. It was worth a try.

Aleksi "Lex" Kilpinen

That would have probably been a typo

Code (here) Select

die("Error importing member");

when I thinks it should have been

die("Error importing member")';


Anyway, do you still need assistance with this?
Slava
Ukraini!
"Before you allow people access to your forum, especially in an administrative position, you must be aware that that person can seriously damage your forum. Therefore, you should only allow people that you trust, implicitly, to have such access." -Douglas

How you can help SMF

Arantor

No there shouldn't be a ' after the ) in that... die() is a language construct and works like that.
Holder of controversial views, all of which my own.


Aleksi "Lex" Kilpinen

Quote from: Arantor on February 23, 2011, 08:38:17 AM
No there shouldn't be a ' after the ) in that... die() is a language construct and works like that.
I stand corrected.
Slava
Ukraini!
"Before you allow people access to your forum, especially in an administrative position, you must be aware that that person can seriously damage your forum. Therefore, you should only allow people that you trust, implicitly, to have such access." -Douglas

How you can help SMF

Advertisement: