<?php
        //DISREGARD COMMENT
        /*
        $hostname="localhost";
        $dbuser = "";
        $dbpass = "";
        $database = "clientexec_test";


        $connection = mysql_connect($hostname, $dbuser, $dbpass) or die (_ERRORDBQUERY);
        mysql_select_db($database, $connection) or die("Can not select database: $database");
        */

        //Get FirstName from custom field table and add to user table
        $query ="SELECT cu.userid, cu.value FROM customuserfields cf, user_customuserfields cu WHERE cf.name='First Name' AND cf.id=cu.customid";
        $result = mysql_query($query) or die("ERROR (Getting First Name from custom fields): $query");
        while(list($uid,$firstname) = mysql_fetch_row($result)){
              $query2 = "UPDATE users SET firstname='$firstname' WHERE id=".$uid;
              $result2 = mysql_query($query2) or die("Updating First Name from custom to user's profile: $query2");
        }

        //Get Last Name from custom field table and add to user table
        $query ="SELECT cu.userid, cu.value FROM customuserfields cf, user_customuserfields cu WHERE cf.name='Last Name' AND cf.id=cu.customid";
        $result = mysql_query($query) or die("ERROR (Getting Last Name from custom fields): $query");
        while(list($uid,$lastname) = mysql_fetch_row($result)){
              $query2 = "UPDATE users SET lastname='$lastname' WHERE id=".$uid;
              $result2 = mysql_query($query2) or die("Updating Last Name from custom to user's profile: $query2");
        }

        //Get Email from custom field table and add to user table
        $query ="SELECT cu.userid, cu.value FROM customuserfields cf, user_customuserfields cu WHERE cf.name='Email' AND cf.id=cu.customid";
        $result = mysql_query($query) or die("ERROR (Getting Email from custom fields): $query");
        while(list($uid,$email) = mysql_fetch_row($result)){
              $query2 = "UPDATE users SET email='$email' WHERE id=".$uid;
              $result2 = mysql_query($query2) or die("Updating Email from custom to user's profile: $query2");
        }

        //Get Organization from custom field table and add to user table
        $query ="SELECT cu.userid, cu.value FROM customuserfields cf, user_customuserfields cu WHERE cf.name='Organization' AND cf.id=cu.customid";
        $result = mysql_query($query) or die("ERROR (Getting Organization from custom fields): $query");
        while(list($uid,$organization) = mysql_fetch_row($result)){
              $query2 = "UPDATE users SET organization='$organization' WHERE id=".$uid;
              $result2 = mysql_query($query2) or die("Updating Organization from custom to user's profile: $query2");
        }
?>
