jakebur01 Posted May 24, 2007 Share Posted May 24, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/52748-solved-order-number-or-tracking-number/ Share on other sites More sharing options...
btherl Posted May 24, 2007 Share Posted May 24, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/52748-solved-order-number-or-tracking-number/#findComment-260465 Share on other sites More sharing options...
jakebur01 Posted May 24, 2007 Author Share Posted May 24, 2007 If info is submitted into the customer table, orders table, and shipping table but not in the credit card table wouldn't it throw things off balance if I were relying on auto_increment? Quote Link to comment https://forums.phpfreaks.com/topic/52748-solved-order-number-or-tracking-number/#findComment-260476 Share on other sites More sharing options...
btherl Posted May 24, 2007 Share Posted May 24, 2007 I don't see why it would be a problem. Is there an additional condition you want to satisfy, such as "There is only every one auto_increment id for one customer" ? Quote Link to comment https://forums.phpfreaks.com/topic/52748-solved-order-number-or-tracking-number/#findComment-260488 Share on other sites More sharing options...
btherl Posted May 24, 2007 Share Posted May 24, 2007 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? Quote Link to comment https://forums.phpfreaks.com/topic/52748-solved-order-number-or-tracking-number/#findComment-260490 Share on other sites More sharing options...
jakebur01 Posted May 24, 2007 Author Share Posted May 24, 2007 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... Quote Link to comment https://forums.phpfreaks.com/topic/52748-solved-order-number-or-tracking-number/#findComment-260493 Share on other sites More sharing options...
btherl Posted May 24, 2007 Share Posted May 24, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/52748-solved-order-number-or-tracking-number/#findComment-260501 Share on other sites More sharing options...
jakebur01 Posted May 24, 2007 Author Share Posted May 24, 2007 what if we want to add an insert on the next page inserting credit card info into table. How would I link the customer id in this table with my customer and orders tables? `Jake Quote Link to comment https://forums.phpfreaks.com/topic/52748-solved-order-number-or-tracking-number/#findComment-260504 Share on other sites More sharing options...
btherl Posted May 24, 2007 Share Posted May 24, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/52748-solved-order-number-or-tracking-number/#findComment-260507 Share on other sites More sharing options...
jakebur01 Posted May 24, 2007 Author Share Posted May 24, 2007 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. ? Quote Link to comment https://forums.phpfreaks.com/topic/52748-solved-order-number-or-tracking-number/#findComment-260511 Share on other sites More sharing options...
btherl Posted May 24, 2007 Share Posted May 24, 2007 Yep, that's exactly it Quote Link to comment https://forums.phpfreaks.com/topic/52748-solved-order-number-or-tracking-number/#findComment-260513 Share on other sites More sharing options...
jakebur01 Posted May 24, 2007 Author Share Posted May 24, 2007 THANK YOU! Quote Link to comment https://forums.phpfreaks.com/topic/52748-solved-order-number-or-tracking-number/#findComment-260517 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.