1 of 2
1
importing members / ip_address
Posted: 06 November 2005 06:55 PM   [ Ignore ]  
Research Assistant
RankRankRank
Total Posts:  421
Joined  12-22-2003

If I want to import members using a MySQL query, do I need to know the IP address of the members’ computer (in order to supply the required ip_address)? Or have I totally misunderstood?

Frank

Profile
 
 
Posted: 06 November 2005 06:57 PM   [ Ignore ]   [ # 1 ]  
Moderator
Avatar
RankRankRankRankRankRankRankRank
Total Posts:  33269
Joined  05-14-2004

Frank, you can find the minimum info needed for a member import in this wiki entry as well as more information in the thread linked therein.

 Signature 
Profile
MSG
 
 
Posted: 06 November 2005 07:15 PM   [ Ignore ]   [ # 2 ]  
Research Assistant
RankRankRank
Total Posts:  421
Joined  12-22-2003

Thanks Lisa - I’ve read the WIKI entry and it was the referenced thread that led me to the WIKI entry, but neither of those items answers my question. I have to import nearly 1,400 member records. I know from the WIKI entry and the thread that ip_address is one of the required pieces of information that needs to be imported, but it doesn’t seem reasonable to expect that I would know the IP addresses of all 1,400 members.

For example, can I just put in any IP address for each record? Will it then be overwritten the first time each member logs in?

Hope that made sense.

Thanks!
Frank

Profile
 
 
Posted: 06 November 2005 07:32 PM   [ Ignore ]   [ # 3 ]  
Research Scientist
Avatar
RankRankRankRankRankRank
Total Posts:  7509
Joined  08-05-2002

You can put in your IP address or 0.0.0.0, and I believe the next time they update their profile their IP address will be updated.  I do not believe it is updated on login.

 Signature 
Profile
 
 
Posted: 07 November 2005 10:02 AM   [ Ignore ]   [ # 4 ]  
Research Assistant
RankRankRank
Total Posts:  421
Joined  12-22-2003

Thanks Paul - that’s helpful. A follow-up question:

Is it possible in the query to include a spot for the email address, but leave it blank so that members have to fill in their own email address once they’ve logged in for the first time? Something like this:

INSERT INTO exp_members (group_id, username, screen_name, password, unique_id, email, ip_address, join_date, firstname, lastname) VALUES ('6', 'sampleusername', 'Sample Screen Name', MD5('samplepassword'), 'sampleuniqueid', '', '0.0.0.0', '1131325140', 'samplefirstname', 'samplelastname');

(firstname and lastname are custom member fields in my database).

Thanks for any help you can offer!

Frank

Profile
 
 
Posted: 07 November 2005 10:08 AM   [ Ignore ]   [ # 5 ]  
Research Scientist
Avatar
RankRankRankRankRankRank
Total Posts:  7509
Joined  08-05-2002

The email address is a required field.  If it is not there, then if they comment there will likely be error messages.  Also, forgot password will not work.  So, while you can do it (and things might turn out alright) it is not recommended.

Custom member fields are stored in the exp_member_data field, and we do not name the field using the short name but rather using the form m_field_id_1 where the number is ascribed to the short and long name of the field (and the various other custom member field settings).

 Signature 
Profile
 
 
Posted: 08 November 2005 08:51 PM   [ Ignore ]   [ # 6 ]  
Research Assistant
RankRankRank
Total Posts:  421
Joined  12-22-2003

Thanks Paul. A few additional questions:

1. Following on your appreciated heads-up about the name for custom member fields, I have two custom member fields - firstname and lastname. In the control panel, they have a “1” and a “2” next to them. Would this mean that I would name them m_field_id_1 and m_field_id_2, respectively, in the query?

2. Since they are in exp_member_data table, can you give me a suggestion for how I would formulate the query(ies) in order to import most of the information into the exp_members table and the information for the custom member fields into the exp_members_data table? Can I do it all with one query or are multiple queries required?

3. Similarly, and trying to comprehend Rick’s initial comment in this thread:

There are two additional tables that must contain a row for each member, correlated with the member_id of the member:

exp_member_data
exp_member_homepage

Would a query (whether it is part of the original query or an additional query) which places the custom member field info into the exp_member_data table also need to have the member_id of the member (and where do I find that - is it the unique_id?)?

4. Finally, do I need to formulate an additional query to create the rows for each member in exp_member_homepage (and what would that query look like?)?

As you can tell, I am worse than a novice when it comes to working with mySQL. I would just hire someone to do it, but my client is a non-profit with limited funds, and I don’t have the funds either. Thanks in advance for any help you can offer - I really appreciate it!

Thanks,
Frank

Profile
 
 
Posted: 09 November 2005 12:39 AM   [ Ignore ]   [ # 7 ]  
Research Scientist
Avatar
RankRankRankRankRankRank
Total Posts:  7509
Joined  08-05-2002

As it is a new member going into the database, you will have to know the inserted member’s member_id value.  This is only known after the insert into exp_members is done.  Really, to do this, you are going to need to use PHP to do the first, query, discover the member_id, and then create an entry into exp_member_data and exp_member_homepage for the new user.  We are looking at a PHP script with multiple queries, and it has to cycle through all of your new members.

If you are unfamiliar with PHP and MySQL, then you might need to have someone help you with this script.  It might look something like this:

<?php

global $DB, $FNS, $IN, $LOC;

$new_members = array();
$new_members[] = array( 'group_id'     => "6",
                        
'username'     => "reedmaniac",
                        
'screen_name'  => 'Paul',
                        
'password'     => "password",
                        
'unique_id'    => $FNS->random('encrypt'),
                        
'email'        => "dude@reedmaniac.com"
                        'ip_address'   
=> $IN->IP,
                        
'join_date'    => $LOC->now,
                        
'firstname'    => 'Paul',
                        
'lastname'     => 'Burdick');
                        
foreach(
$new_members as $new_member)
{
    $core
= $new_member; unset($new_member['firstname']); unset($new_member['lastname']);
    
$DB->query($DB->insert_string('exp_members', $core));
    
    
$member_id = $DB->insert_id;
    
    
$cust_fields = array();
    
$cust_fields['member_id'] = $member_id;
    
$cust_fields['m_field_id_1'] = $new_member['firstname'];
    
$cust_fields['m_field_id_2'] = $new_member['lastname'];
    
$DB->query($DB->insert_string('exp_member_data', $cust_fields));
    
    
$DB->query($DB->insert_string('exp_member_homepage', array('member_id' => $member_id)));
}

?>

 Signature 
Profile
 
 
Posted: 11 December 2005 05:03 AM   [ Ignore ]   [ # 8 ]  
Grad Student
Rank
Total Posts:  43
Joined  12-24-2003

I’m following this thread, but it requires some time to figure out how this all is going to work.

Why not make a module that allows all users to import member lists? I mean, it would make EE much more visible and popular: all members on a list will notice EE’s brilliance!

Profile
 
 
Posted: 11 December 2005 12:05 PM   [ Ignore ]   [ # 9 ]  
Research Scientist
Avatar
RankRankRankRankRankRank
Total Posts:  7509
Joined  08-05-2002

It is on our to do list, but it has not been finished because we are working on something else in tandem with it that might change the entire approach.

 Signature 
Profile
 
 
Posted: 11 December 2005 01:23 PM   [ Ignore ]   [ # 10 ]  
Grad Student
Rank
Total Posts:  43
Joined  12-24-2003

That soiunds interesting! Any idea when this will be ready?

Profile
 
 
Posted: 07 January 2006 03:54 PM   [ Ignore ]   [ # 11 ]  
Grad Student
Avatar
Rank
Total Posts:  83
Joined  08-04-2003

Very interesting thread. I read the Wiki and the above instructions too but have some questions left.

First the member_id. The members already in the tables are numbered from 1 to 9.  Is it not possible to simply apply the next numbers to the next members?

Second.  The password. The wiki says “can be MD5 or SHA1”. I do not understand that. Can I put a default word there for the 300 new members I want to introduce through MySQL?

Third. The unique_id. The wiki says: a random 32 character string, used for session cookies.  I suppose that I can use the same for all new users?

Profile
 
 
Posted: 08 January 2006 04:34 AM   [ Ignore ]   [ # 12 ]  
Moderator
Avatar
RankRankRankRankRankRankRank
Total Posts:  12755
Joined  04-29-2002
FransG - 07 January 2006 03:54 PM

Very interesting thread. I read the Wiki and the above instructions too but have some questions left.

First the member_id. The members already in the tables are numbered from 1 to 9.  Is it not possible to simply apply the next numbers to the next members?

You could, but Paul gives you a method to grab that number to use when writing out data to the database.

$member_id = $DB->insert_id;

Second.  The password. The wiki says “can be MD5 or SHA1”. I do not understand that. Can I put a default word there for the 300 new members I want to introduce through MySQL?

Here’s a way of doing it..

$password = 'apple';
$password = md5($password);

Third. The unique_id. The wiki says: a random 32 character string, used for session cookies.  I suppose that I can use the same for all new users?

No, again Paul gives you the code for this:

'unique_id'    => $FNS->random('encrypt'),

 Signature 

Quick Reference - EE Trial Options - EE Wiki - Docs for updating a build

Profile
MSG
 
 
Posted: 08 January 2006 06:58 AM   [ Ignore ]   [ # 13 ]  
Grad Student
Avatar
Rank
Total Posts:  83
Joined  08-04-2003

Thank you Sue. I was already trying to use MySQLadmin; I can enter data for the tables but then I run into problems with the password indeed.

So now trying a little bit adapted form of Paul’s PHP;

global $DB, $FNS, $IN, $LOC;
$password = "theword";
$new_members = array();
$new_members[] = array( 'group_id'     => "5",
                        
'username'     => "Paulus",
                        
'screen_name'  => 'Paul',
                        
'password'     => md5($password),
                        
'unique_id'    => $FNS->random('encrypt'),
                        
'email'        => "g.tester@oosterlicht.nl",
                        
'ip_address'   => "0.0.0.0",
                        
'join_date'    => $LOC->now,);
                        
foreach(
$new_members as $new_member)
{
    $core
= $new_member;
    
$DB->query($DB->insert_string('exp_members', $core));
    
$member_id = $DB->insert_id;
    
$DB->query($DB->insert_string('exp_member_data', array('member_id' => $member_id)));
    
$DB->query($DB->insert_string('exp_member_homepage', array('member_id' => $member_id)));
}
?>


Unfortunately now I run into :

Call to a member function on a non-object in /www/htdocs/leraar/testinvoerlid.php on line 9

where line 9 is the one of the unique_id.
Could this be caused by the php-file being in the wrong folder?

Profile
 
 
Posted: 08 January 2006 07:15 AM   [ Ignore ]   [ # 14 ]  
Moderator
Avatar
RankRankRankRankRankRankRank
Total Posts:  12755
Joined  04-29-2002

I run this sort of code from inside an EE template. Not in a .php file of any sort.

The EE template has parsing set to input.

I also read through a .csv file to get the values I need and parse them to create the fields I need.

 Signature 

Quick Reference - EE Trial Options - EE Wiki - Docs for updating a build

Profile
MSG
 
 
Posted: 08 January 2006 12:04 PM   [ Ignore ]   [ # 15 ]  
Grad Student
Avatar
Rank
Total Posts:  83
Joined  08-04-2003

Thanks again Sue.
In spite of my very limited PHP-knowledge I have the 300 members in the database now; using a template like you described.

Profile
 
 
Posted: 12 February 2006 10:44 AM   [ Ignore ]   [ # 16 ]  
Grad Student
Rank
Total Posts:  75
Joined  11-15-2003

>The email address is a required field.  If it is not there, then if they comment there will likely be error messages.

What if comments were not and never were allowed. Could you get away with a dummy email address?

Profile
 
 
Posted: 26 April 2006 11:11 PM   [ Ignore ]   [ # 17 ]  
Summer Student
Avatar
Total Posts:  11
Joined  12-13-2003

And for other peolple with a very limited PHP-knowledge can you describe all your steps with an example of the .csv and the template you created?

Profile
 
 
Posted: 27 April 2006 12:52 PM   [ Ignore ]   [ # 18 ]  
Grad Student
Avatar
Rank
Total Posts:  83
Joined  08-04-2003

I know very well that it should be much better to include some reading of a file instead of this including the contents in the script. But this worked for me. I was in a hurry.

<?php
global $DB, $FNS, $IN, $LOC;
$password = "thepassword";
$new_members = array();
$new_members[]=array('group_id'=>"5",'username'=>"John",'screen_name'=>"mi",'password'=>md5($password),'unique_id'=>$FNS->random('encrypt'),'email'=>"m.nameone@domainname.nl",'ip_address'=>"0.0.0.0",'join_date'=>$LOC->now,);
$new_members[]=array('group_id'=>"5",'username'=>"Mary",'screen_name'=>"ms",'password'=>md5($password),'unique_id'=>$FNS->random('encrypt'),'email'=>"somebodyelse@domainname.nl",'ip_address'=>"0.0.0.0",'join_date'=>$LOC->now,);

and
on and on

foreach($new_members as $new_member)
{
    $core
= $new_member;
    
$DB->query($DB->insert_string('exp_members', $core));
    
$member_id = $DB->insert_id;
    
$DB->query($DB->insert_string('exp_member_data', array('member_id' => $member_id)));
    
$DB->query($DB->insert_string('exp_member_homepage', array('member_id' => $member_id)));
    echo
"okay<br>";
}
?>

Zie net dat je ook Nederlander bent. Grappig

Profile
 
 
   
1 of 2
1
 
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 1149, on July 16, 2007 09:33 AM
Total Registered Members: 66391 Total Logged-in Users: 30
Total Topics: 84716 Total Anonymous Users: 19
Total Replies: 454701 Total Guests: 204
Total Posts: 539417    
Members ( View Memberlist )