I would like to use the customer ID as an account number, however instead of auto_increment values, I would like to have a number automatically assigned when a user creates their account.
So I had the bright idea
(or so I thought) of using a rand statement to auto generate a random number for the user account. First steps, I went into the database, and edited the customers_id structure, disabling the auto_increment and changed the data type from INT to BIGINT.
Step two, edit create_account.php. No this is where it gets tricky. I started off by adding the following code:
PHP Code:
$customers_id = rand(1000000000, 9999999999);
and then called the variable in the SQL array further down in the page:
PHP Code:
'customers_id' => $customers_id
Now to test my theory.... I created a fake user. Then I went into the db and upon examining the customers table, the value shows up as 0. So I tried removing the variable instance and changed the array code to:
PHP Code:
'customers_id' => rand(1000000000, 9999999999)
I cleared the 3 db tables and created another fake user, tada... SAME results.
I am at a loss here. I may not be an expert at PHP but I know enough about OOP and can get a feel for it by looking at all of the other code. Anyone have any ideas?
Is there another file that maybe I need to edit as well? I didn't figure so. I edited this file to add the company name to the array, since I didn't see the code for it, and when I would test an account with a company name, the name wouldnt show up anywhere. Upon investigation, I found that I didn't even have a company field in the customers table, so I added it, set it to NULL (in case a customer does not have a company name) and added the variable to the array. That worked just fine for me... it showed on account details, etc. (Yes I could Require the company name, but that would force all customers to have a company name for registration and my site serves both businesses and consumers, so it would not make sense to Require it... in case anyone was wondering why I chose to do it this way.) But I can't seem to figure out the account number. I understand the reasoning behind the auto_increment and not being a good idea to mess with it "at my risk" but I would like random account numbers that do not have to be manually updated. And yes, there is a SMALL probability that the node may generate a duplicate, in which a rare case would just require the user to reload (which generates a new RAND) and fill in the create account form again since the db will not allow duplicates as a PK. But the important use for this is when customers call in about their accounts, that is the way their accounts are tracked.
FOR THE RECORD: this is a secondary sandbox site/db. only test accounts have been setup on this site and a few sample products. I can simply truncate the address book, customers, info, and session tables at will. Once I get all of this figured out on the sandbox site, I will apply what I need to my test site, which is fully configured and ready for FTP(less my mods, respectively.)
Thanks for your time in reading this rather exhaustive post, and I hope to hear from your creative and technical minds soon!
Bookmarks