help with script please
| From: | Richard A. Foreman II | Date: | Sun, 07 Jan 2001 00:52:03 +0000 |
| Subject: | help with script please | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-33069@lists.php.net to get a copy of this message | ||
First, I am ENTIRELY new to php, so thanks in advance for the help!
I have a folder on my server: /usr/local/etc/httpd/cgi-bin/Members/
that contains several files, called: 00000002.cgi all the way through
00000198.cgi
These files all have data in the same format:
username
plaintextpassword
email
na
na
na
na
na
na
na
datereg
na
na
na
na
I am trying to get the username and password from all of these files and
create a new user entry in a mysql database for each user.
I have a php script written, but it gives the following error on line #38,
which is $member = file($members[$i]);
The error it gives is:
Warning: file("00000198.cgi") - No such file or directory in
/usr/local/etc/httpd/htdocs/board/ubb.php on line 38
It does this for EVERY file.
Here is the script in it's entirety. Can someone please help me out?
<?
// export ubb members to phpBB
$memberpath = "/usr/local/etc/httpd/cgi-bin/Members";
$dbhost = "localhost";
$dbname = "forum";
$dbuser = "richfore";
$dbpass = "*******";
// open directory, load member filenames into array
$handle = opendir($memberpath);
$a = 0;
while ($file = readdir($handle))
{
if((preg_match('/00/', $file)))
{
$members[$a] = $file;
echo "<br>file $a: $file";
$a++;
}
}
closedir($handle);
// count remaining elements of array
$i = count($members) - 1;
// insert data into phpBB mysql database
$db = mysql_connect("$dbhost", "$dbuser", "$dbpass") or
die("<P>Error: could not connect to the database. Using username $dbuser
and password $dbpass.<BR>Please go back and try again.");
@mysql_select_db("$dbname", $db) or die ("<P>Error: Could not open
database.");
// for each member, gather data for import
echo "<br>Processing $i members .";
while ( $i >= 0 ) {
$member = file($members[$i]);
$username = addslashes(trim($member[0]));
$user_password = md5(trim($member[1]));
echo ".";
$sql = "
insert into users
(username, user_password )
values
('$username', '$user_password' )
";
$result = mysql_query($sql, $db) or die("<P>Could not query the database!
Check syntax! <br>Failed inserting $username ($members[$i])");
$i--;
}
echo "<P>Done Processing!";
exit;
?>