How to correct thousands of users fields

27.11. How to correct thousands of users fields

You have discovered a problem where several (thousands) of your users were added through the edit user screen and ended up with a space (or in some cases 2 spaces) inserted before the e-mail address and other fields. Your bulk e-mails are coming through, but you are not able to effectively search or sort users because of this space. In situations like this, you must be able to correct thousands of users fields, without having to do it manually. Proceed as follows (see exporting nuke_users data):

Create the following PHP script with a decent text editor (Chapter 11):

<?php
include("mainfile.php");
global $prefix, $db, $dbi;
$sql = "SELECT * FROM ".$prefix."_users ORDER BY user_id ASC";
$result = $db->sql_query($sql);
while ($row = $db->sql_fetchrow($result)) {
  $userid = $row['user_id'];
  $oldemail = $row["user_email"];
  $newemail = str_replace (" ","",$oldemail);
  $update = $db->sql_query("UPDATE ".$prefix.
  "_users set user_email='$newemail' where user_id='$userid'");
}
?>

Upload it in the same directory where also the mainfile.php of your PHP-Nuke is located (sinse it includes mainfile.php with a relative, as opposed to absolute, path, it will not work if you upload it in a different place!). Point your browser to it - and the script will do the rest for you!

Caution Backup your database!
 

Always make a backup of your database before trying such a thing! If it breaks, you keep both pieces.


Help us make a better PHP-Nuke HOWTO!

Want to contribute to this HOWTO? Have a suggestion or a solution to a problem that was not treated here? Post your comments on my PHP-Nuke Forum!

Chris Karakas, Maintainer PHP-Nuke HOWTO

 

Site Info v2.2.2

Last SeenLast Seen
Server TrafficServer Traffic
  • Total: 338,817,333
  • Today: 66,564
Server InfoServer Info
  • Oct 16, 2017
  • 07:27 pm PDT
 
 

Daily Inspiration