Google Answers Logo
View Question
 
Q: help with PHP mySQL script to convert between PHPnuke and Invision Forum ( Answered 5 out of 5 stars,   0 Comments )
Question  
Subject: help with PHP mySQL script to convert between PHPnuke and Invision Forum
Category: Computers > Programming
Asked by: alakon2-ga
List Price: $4.00
Posted: 05 Oct 2003 19:33 PDT
Expires: 04 Nov 2003 18:33 PST
Question ID: 262991
Jchef,

I have a PHP script that converts members from a PHPnuke 6.0 website
to an Invision Bulletin Board v. 1.2. The problem with the script is
that members appear to duplicate every time the script is run, which
is often, as a I have a cron job running it every four hours. I know
this is a little wasteful, but it is the easiest way (I am not a
programmer!) for me to sync membership lists. I would appreciate it if
you could help me rewrite the script so that the old members are not
duplicated over and over.

<?php
/************************************/
/* Import phpNuke6.0 users to IPB   */
/* By Holbrookau                    */
/************************************/
require("mainfile.php");
global $dbi, $prefix;

$ipbprefix = "ibf"; // Prefix of your IPB tables - edit if required.

$nukenum = (sql_num_rows(sql_query("select * from ".$prefix."_users",
$dbi))); $sql = "SELECT id FROM $ipbprefix"._members." ORDER BY id
DESC LIMIT 1"; $result = sql_query($sql, $dbi);
list($id) = sql_fetch_row($result, $dbi);

echo "<b>Getting users from phpNuke..</b><br><br>"; 

$sql = "SELECT uid, uname, email, pass FROM ".$prefix."_users WHERE
uid > 2"; $result = sql_query($sql, $dbi);
	if (!$result) {
			echo "Error - Could not get members from <b>".$prefix."_users</b>
table";
			return;
		}
echo "<b>Adding members to IBF..</b><br><br>";
while (list($uid, $uname, $email, $pass) = sql_fetch_row($result,
$dbi)) {
	$result2 = sql_query("INSERT into ".$ipbprefix."_members (id,mgroup,
name, password, email) values ('$uid' + ('$id'-2), 3, '$uname',
'$pass', '$email')", $dbi);
	if (!$result2) {
			echo "Error - Could not add users to <b>".$ipbprefix."_members</b>
table";
			return;
		}
	echo "$uid $uname";
	echo "<br>";
	}
echo "<br><b>".$nukenum." phpNuke users have been successfully added
as IPB members.</b><br>Only usernames, email addresses and (encrypted)
passwords have been imported. Please check your
<b>".$ipbprefix."_members</b> table for duplicate users."; ?>

Clarification of Question by alakon2-ga on 05 Oct 2003 19:33 PDT
Ignore the first line "Jchef"!
Answer  
Subject: Re: help with PHP mySQL script to convert between PHPnuke and Invision Forum
Answered By: webadept-ga on 06 Oct 2003 09:20 PDT
Rated:5 out of 5 stars
 
Hi, 

Here you go. I put in a sql check to see if the user name exists
before the insert. If the username already exists, it by-passes the
instert, otherwise it functions as normal.

<?php 
/************************************/ 
/* Import phpNuke6.0 users to IPB   */ 
/* By Holbrookau                    */ 
/************************************/ 
require("mainfile.php"); 
global $dbi, $prefix; 
 
$ipbprefix = "ibf"; // Prefix of your IPB tables - edit if required. 
 
$nukenum = (sql_num_rows(sql_query("select * from ".$prefix."_users",
$dbi))); $sql = "SELECT id FROM $ipbprefix"._members." ORDER BY id 
DESC LIMIT 1"; $result = sql_query($sql, $dbi); 
list($id) = sql_fetch_row($result, $dbi); 
 
echo "<b>Getting users from phpNuke..</b><br><br>";  
 
$sql = "SELECT uid, uname, email, pass FROM ".$prefix."_users WHERE 
uid > 2"; $result = sql_query($sql, $dbi); 
 if (!$result) { 
   echo "Error - Could not get members from <b>".$prefix."_users</b> 
table"; 
   return; 
  } 
echo "<b>Adding members to IBF..</b><br><br>"; 
while (list($uid, $uname, $email, $pass) = sql_fetch_row($result, 
$dbi)) { 
  $check_r = sql_query("select count(*) as countck from "
.$ipbprefix."_members
                        where name = '$uname'", $dbi);
  $a = mysql_fetch_array($check_r);
  if($a['countck'] <= 0 )
   {
     $result2 = sql_query("INSERT into ".$ipbprefix."_members
(id,mgroup,
      name, password, email) values ('$uid' + ('$id'-2), 3, '$uname',
      '$pass', '$email')", $dbi); 
 if (!$result2) { 
   echo "Error - Could not add users to <b>".$ipbprefix."_members</b>
table"; 
   return; 
  } // end check insert result 
  
 } // end if check that there are no duplicates // 
  
 echo "$uid $uname"; 
 echo "<br>"; 
 }  // end insert while loop 
 
echo "<br><b>".$nukenum." phpNuke users have been successfully added 
as IPB members.</b><br>Only usernames, email addresses and (encrypted)
passwords have been imported. Please check your 
<b>".$ipbprefix."_members</b> table for duplicate users."; ?>



thanks, 

webadept-ga

Request for Answer Clarification by alakon2-ga on 07 Oct 2003 18:54 PDT
Thank you for the modification. The script works fine -- however the
output is misleading. Can you please change it so that the outputted
text is the new members added rather then a complete listing of all
membership?

Clarification of Answer by webadept-ga on 07 Oct 2003 23:39 PDT
Sure.. I'll log in and do this in the morning. Glad it is working for
you.. until then.

webadept-ga

Clarification of Answer by webadept-ga on 08 Oct 2003 15:19 PDT
This should have everything in the right place for printing

<?php  
/************************************/  
/* Import phpNuke6.0 users to IPB   */  
/* By Holbrookau                    */  
/************************************/  
require("mainfile.php");  
global $dbi, $prefix;  
  
$ipbprefix = "ibf"; // Prefix of your IPB tables - edit if required.  
  
$nukenum = (sql_num_rows(sql_query("select * from ".$prefix."_users",
$dbi))); $sql = "SELECT id FROM $ipbprefix"._members." ORDER BY id  
DESC LIMIT 1"; $result = sql_query($sql, $dbi);  
list($id) = sql_fetch_row($result, $dbi);  
  
echo "<b>Getting users from phpNuke..</b><br><br>";   
  
$sql = "SELECT uid, uname, email, pass FROM ".$prefix."_users WHERE  
uid > 2"; $result = sql_query($sql, $dbi);  
 if (!$result) {  
   echo "Error - Could not get members from <b>".$prefix."_users</b>  
table";  
   return;  
  }  
echo "<b>Adding members to IBF..</b><br><br>";  
while (list($uid, $uname, $email, $pass) = sql_fetch_row($result,  
$dbi)) {  
  $check_r = sql_query("select count(*) as countck from "
.$ipbprefix."_members
                        where name = '$uname'", $dbi); 
  $a = mysql_fetch_array($check_r); 
  if($a['countck'] <= 0 ) 
   { 
     $result2 = sql_query("INSERT into ".$ipbprefix."_members
(id,mgroup,
      name, password, email) values ('$uid' + ('$id'-2), 3, '$uname',
      '$pass', '$email')", $dbi); 


      
 	if (!$result2) 
	{  
   	  echo "Error - Could not add users to <b>".$ipbprefix."_members</b> table";  
          return;  
        } // end check insert result  
   
	else 
 	{
      
 		echo "$uid $uname";  
 		echo "<br>";  

 	} // if all is fine print the names. 

   
 } // end if check that there are no duplicates //  

 }  // end insert while loop  
  
echo "<br><b>".$nukenum." phpNuke users have been successfully added  
as IPB members.</b><br>Only usernames, email addresses and (encrypted)
passwords have been imported. Please check your  
<b>".$ipbprefix."_members</b> table for duplicate users."; 

?> 



------------

Thanks

webadept-ga
alakon2-ga rated this answer:5 out of 5 stars and gave an additional tip of: $1.00
Thank you for an excellent answer! I will be looking for your services
in the future!

Comments  
There are no comments at this time.

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy