FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » FUDforum » How To » Help with fud_add_user
Show: Today's Messages :: Polls :: Message Navigator
Switch to threaded view of this topic Create a new topic Submit Reply
- Help with fud_add_user [message #34975] Wed, 29 November 2006 04:21 Go to next message
appscontent   United States
Messages: 33
Registered: November 2006
Karma: 0
Member
Okay ...so I am not a PHP developer! I need help with the following ... since it doesn't add the users.

<?php
include_once("/home/mypath/FUDforum/include/GLOBALS.php");
include ("fudapi.inc.php");
$filename = "/home/my/path/testusers.txt";
$fh = fopen ($filename, "r") or die("Could not open file");

while (!feof($fh))
{
$fields = fgetcsv($fh, 20);
$userid = fud_add_user($fields, &$errcode);
}

fclose ($fh);
?>


The csv file contains the following data:

user1,password1,email1(at)noplace(dot)com,name1
user2,password2,email2(at)noplace(dot)com,name2
user3,password3,email3(at)noplace(dot)com,name3
user4,password4,email4(at)noplace(dot)com,name4
user5,password5,email5(at)noplace(dot)com,name5


- Re: Help with fud_add_user [message #34977 is a reply to message #34975] Wed, 29 November 2006 15:13 Go to previous messageGo to next message
Ilia is currently offline  Ilia   Canada
Messages: 13241
Registered: January 2002
Karma: 0
Senior Member
Administrator
Core Developer
The fud_add_user() takes an associated array described in fudapi.inc.php, you cannot pass it the array returned by fgetcsv() because the forum can't tell which fields go where like that.

FUDforum Core Developer
- Re: Help with fud_add_user [message #34985 is a reply to message #34977] Thu, 30 November 2006 11:59 Go to previous messageGo to next message
appscontent   United States
Messages: 33
Registered: November 2006
Karma: 0
Member
So my question boils down to how do I exactly do what you've just described? I am limited technically, I am just trying to load my users in your fantastic forums (very cool software). I don't understand everything in fudapi.inc.php.

I've tried doing the following but it doesn't work.

$vals = array('login','passwd','email','name');
$vals[0] = fields[0];
$vals[1] = fields[1];
$vals[2] = fields[2];
$vals[3] = fields[3];
$usid = fud_add_user($vals, &$err);
}

I appreciate all your help. I sorry for my ingnorance but I just need some PHP coding help with holl I should call the function fud_add_user. Could you show me what you mean so I can adapt it to my script?

Thanks
- Re: Help with fud_add_user [message #34988 is a reply to message #34985] Thu, 30 November 2006 16:52 Go to previous messageGo to next message
Ilia is currently offline  Ilia   Canada
Messages: 13241
Registered: January 2002
Karma: 0
Senior Member
Administrator
Core Developer
you need to do this:

<?php
$vals 
= array();
$vals['login'] = $fields[0];
$vals['passwd'] = $fields[1];
$vals['email'] = $fields[2];
$vals['name'] = $fields[3];
?>



FUDforum Core Developer
- Re: Help with fud_add_user [message #35002 is a reply to message #34975] Fri, 01 December 2006 14:30 Go to previous messageGo to next message
appscontent   United States
Messages: 33
Registered: November 2006
Karma: 0
Member
Thanks for the help ... made some progress but get the following in the Error Log Browser:

(/home/eunivers/FUDforum/include/theme/default/db.inc:72
/home/eunivers/FUDforum/include/theme/default/db.inc:176
/home/eunivers/FUDforum/scripts/fudapi.inc.php:676
/home/eunivers/FUDforum/scripts/addusercvs.php:15
) 1054: Unknown column 'e' in 'field list'
Query: INSERT INTO fud26_users ( login, alias, passwd, name, email, icq, aim, yahoo, msnm, jabber, affero, posts_ppg, time_zone, bday, last_visit, conf_key, user_image, join_date, location, theme, occupation, interests, referer_id, last_read, sig, home_page, bio, users_opt, reg_ip ) VALUES ( 'e', 'e', 'e', 'e', 'e', 0, 'e', 'e', 'e', 'e', 'e', 0, 'e', 0, 0, 'e', 'e', e, 'e', 0, 'e', 'e', 0, 0, 'e', 'e', 'e', 0, -1 )
Server Version: 4.0.25-standard


Here's my script ...


<?php
include_once("/home/eunivers/FUDforum/include/GLOBALS.php");
include ("fudapi.inc.php");
$filename = "/home/eunivers/bin/testusers.txt";
$fh = fopen ($filename, "r") or die("Could not open file");
while (!feof($fh))
{
$fields = fgetcsv($fh, 20);
$err = 0;
$vals = array();
$vals['login'] = $fields[0];
$vals['passwd'] = $fields[1];
$vals['email'] = $fields[2];
$vals['name'] = $fields[3];
$usid = fud_add_user($vals, &$err);
fclose ($fh);
?>


Here's my CSV data file ...


user1,password1,email1(at)noplace(dot)com,name1
user2,password2,email2(at)noplace(dot)com,name2
user3,password3,email3(at)noplace(dot)com,name3
user4,password4,email4(at)noplace(dot)com,name4
user5,password5,email5(at)noplace(dot)com,name5

[Updated on: Fri, 01 December 2006 14:33]

Report message to a moderator

- Re: Help with fud_add_user [message #35013 is a reply to message #35002] Fri, 01 December 2006 15:36 Go to previous message
Ilia is currently offline  Ilia   Canada
Messages: 13241
Registered: January 2002
Karma: 0
Senior Member
Administrator
Core Developer
Your first problem is that your fgetcsv() call is made with a buffer that is too small. You need to change 20 to 4096, otherwise you are only reading partial data.



FUDforum Core Developer
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: fudForum within a trusted intranet
Next Topic: How to convert all FUDforum from ISO-8859-1 to UTF-8?
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Fri Jan 24 16:40:45 GMT 2025

Total time taken to generate the page: 0.05000 seconds