I'm trying to make a cart. I have a couple of pull-down menus, categorized into group of items etc.
The process is like this:
for example, on form-1 there is a pull-down menu, a user can select an item and click the update-cart button. Cart gets updated. A user can still select another item and update the same cart. The same goes for other pull down menus/forms. Selections can be made and cart will be updated. Things are working ok, and my DB is getting updated correctly. The contents of the cart are being displayed to the user for the purpose of editing / deleting an item previously added to the cart.
When I try to simulate being 1-user, things work fine. If I try using the tool from two different computers(Im running a webserver on my LAN), I can see the contents of the DB(cart) "ordered" from computer-1 on computer-2 eventhough Ive not ordered anything from computer-2.
So I thought about having a uniqueID from( a random-number and date )to be used to differentiate simultaneous users. This value gets updated into my table and the specific orders mapped to the UniqueID should get displayed only to the user.
I tried to include a unique key/value with code below:
Code: Select all
<?php
//require statements
//generate random order-filename
$OrderNo = rand(0,500);
$OrderDate = date("FjY");
$Key= "$OrderDate$OrderNo";
?>
//html code comes next
questions:
1) How do I make sure the random number is not re-run for every click of the submit button?
2) is the above the best approach considering my description.
3) are sessions applicable here considering the form is posting to the same page?