Jump to content

[SOLVED] order number or tracking number


jakebur01

Recommended Posts

I need to create some kind of random number within a persons session that can be inserted into a customer id column for their orders, customer, and credit card tables. Unless their is a better way to link a customers information together between a few tables besides using auto increment. Things could get screwed up for me if I use auto increment, especially if someone submits their information but does not actually place an order.

 

My question is " How can I create a random order number that can be used within a persons session and will stay the same throughout the whole program for that one person? "

 

I have just started learning about sessions so please bear with me.

 

Thank you,

 

Jake

Link to comment
Share on other sites

How does someone submitting information but not placing an order cause trouble with auto_increment?

 

There's essentially no difference between auto_increment and randomly generated ids, except that auto_increment ids are in order.  In practice, they both act identically.

 

To generate a random number, you can use mt_rand().  Then check the number is unused, and add it into your $_SESSION[] array.  You might want to provide customers with a method to recover old sessions, such as providing an order number.  It's a trade-off between security and ease of use always.

Link to comment
Share on other sites

Oh wait.. I think I get what you are saying.

 

The "session identifier" is only auto_increment in ONE table.  In all other tables, it is set to the same value.  So it can never be out of sync, because it's only ever automatically incremented in that one source table.

 

So, you would enter data into the customer table (for example), and grab the next auto_increment id.  Then you would use THAT id to put data into the other tables.  You wouldn't rely on a seperate auto_increment in the other tables and hope that it matches up.  Is that what you're worried about?

Link to comment
Share on other sites

ha.. yea....  so I would need to have the credit card script check to see what the last order number is in the customers table the auto increment from that??

 

I'm starting to visualize all this.... It just takes me a couple of times to get stuff...

Link to comment
Share on other sites

Hmm.. first we need to clear up what you are identifying.  Do you want a unique id for every customer?  Because that is not the same as a unique id for each session.  Each customer can have many sessions (and one session can have many customers, for shared computers).

 

So you can have an auto_increment customer identifier in your customers table, an auto_increment order identifier in your orders table (the orders table will also store customer_id as well as order_id).  Whenever a user makes an order, you create a new order in the orders table, and insert that customer's id into that row.  So there's now a link between the customer and their order.

 

The shipping table can store the order_id value as well.  It can also store the customer_id if you want, although you could find that by linking via the orders table back to the customers table.  That's what "JOIN" is for in SQL.

 

You might want to look through some examples, like the standard "employee" tables used for demonstrating SQL, to get the idea.  Look for "SQL tutorials" on google :)

 

 

Link to comment
Share on other sites

Since it's in the same session, you can store the customer id like this:

 

<?
session_start();
$_SESSION['customer_id'] = $customer_id;

 

Then in the following page, you can get it back:

 

<?
session_start();
$customer_id = $_SESSION['customer_id'];

 

Is that what you're looking for?  I'm not sure what level your understanding of sessions is at, so I'm not sure what it is you're looking for.

 

You can do the same with order_id, storing it in $_SESSION.

 

Then when the credit card details are entered, you can put the customer_id and/or order_id in the credit card info table, so it can be linked back.  You'll have the ids available in $_SESSION.

Link to comment
Share on other sites

I see what your saying. So, after I insert the data into the customers table and orders table. Then, I retrieve the customer id or order id that the mysql database auto_incremented,    store it into a session,        then get the session on my credit card page ,......then insert the customer or order id into the credit card table along with the credit card info.  ?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.