Jump to content

auto increment on primary key when browser is refreshed


samantha_chan1

Recommended Posts

[b]I am currently generating a receipt when the order ID as a primary key when an auto increment function. But when i refresh the page, the order ID will automatically increase by itself. How should i avoid this incident from happening? I do not what an auto increment in order_id when users press Refresh (F5).
[/b]

my script goes here:

<?php

session_start();
include "user_session.php";
include "../database.php";
$sid = session_id();

//to deduct the total price from the balance
$balance = $balance - $total;
$query = mysql_query("update user set amount = '$balance' where user_id='$user_id'");


//put the order placed by the user to ordering to get the order ID
$to_ordering = mysql_query("INSERT INTO ordering VALUES (NULL, '$user_id', '$total', '$date_time', now())");

$order_id = mysql_insert_id();


$cart = mysql_query("SELECT * from temp_cart WHERE cart_sess_id='$sid'");
//put the data into orderlist table one row at a time from temp_cart table
$row = mysql_num_rows($cart);

for($i=0; $i<$row; $i++){
while ($row2 = mysql_fetch_array($cart)) {
extract ($row2);
$to_orderlist = mysql_query("INSERT INTO orderlist (order_id, food_id, quantity, status)
VALUES ('$order_id','$food_id','$qty', 'Not Ready')");
}
}

//delete from temp_cart table
$delete=mysql_query("DELETE FROM temp_cart WHERE cart_sess_id='$sid'");
?>
Link to comment
Share on other sites

[!--quoteo(post=363076:date=Apr 9 2006, 01:46 PM:name=samantha)--][div class=\'quotetop\']QUOTE(samantha @ Apr 9 2006, 01:46 PM) [snapback]363076[/snapback][/div][div class=\'quotemain\'][!--quotec--]
[b]I am currently generating a receipt when the order ID as a primary key when an auto increment function. But when i refresh the page, the order ID will automatically increase by itself. How should i avoid this incident from happening? I do not what an auto increment in order_id when users press Refresh (F5).
[/b]

my script goes here:

<?php

session_start();
include "user_session.php";
include "../database.php";
$sid = session_id();

//to deduct the total price from the balance
$balance = $balance - $total;
$query = mysql_query("update user set amount = '$balance' where user_id='$user_id'");


//put the order placed by the user to ordering to get the order ID
$to_ordering = mysql_query("INSERT INTO ordering VALUES (NULL, '$user_id', '$total', '$date_time', now())");

$order_id = mysql_insert_id();


$cart = mysql_query("SELECT * from temp_cart WHERE cart_sess_id='$sid'");
//put the data into orderlist table one row at a time from temp_cart table
$row = mysql_num_rows($cart);

for($i=0; $i<$row; $i++){
while ($row2 = mysql_fetch_array($cart)) {
extract ($row2);
$to_orderlist = mysql_query("INSERT INTO orderlist (order_id, food_id, quantity, status)
VALUES ('$order_id','$food_id','$qty', 'Not Ready')");
}
}

//delete from temp_cart table
$delete=mysql_query("DELETE FROM temp_cart WHERE cart_sess_id='$sid'");
?>
[/quote]

sorry, not cleared. i just tell a oral solution. that is ... if the order id was given in a script like orders.php. and then your operations are done in operations.php which contains your above codings. let in orders.php you are using a text field and a submit button. then you can check if the submit button was clicked by isset();

[b]This is just an alternate solution. if your problem is accurately not like this, then please explain it clearly. if any one know solution for his problem then please post here.[/b]
Link to comment
Share on other sites

my script goes here:

<?php

session_start();
include "user_session.php";
include "../database.php";
$sid = session_id();

//to deduct the total price from the balance
$balance = $balance - $total;
$query = mysql_query("update user set amount = '$balance' where user_id='$user_id'");


//put the order placed by the user to ordering to get the order ID
$to_ordering = mysql_query("INSERT INTO ordering VALUES (NULL, '$user_id', '$total', '$date_time', now())");

$order_id = mysql_insert_id();


$cart = mysql_query("SELECT * from temp_cart WHERE cart_sess_id='$sid'");
//put the data into orderlist table one row at a time from temp_cart table
$row = mysql_num_rows($cart);

for($i=0; $i<$row; $i++){
while ($row2 = mysql_fetch_array($cart)) {
extract ($row2);
$to_orderlist = mysql_query("INSERT INTO orderlist (order_id, food_id, quantity, status)
VALUES ('$order_id','$food_id','$qty', 'Not Ready')");
}
}

//delete from temp_cart table
$delete=mysql_query("DELETE FROM temp_cart WHERE cart_sess_id='$sid'");
?>
[/quote]


actually this script is posted at the beginning of the script called paid.php. which means that it has html codes at the bottom of the script to display the interface of the web. So from this script, i see that every time this browser is refreshed, the query ----- $to_ordering = mysql_query("INSERT INTO ordering (order_id, user_id, total_price, collection_date, purchase_date) VALUES (NULL, '$user_id', '$total', '$date_time', now())");----- will execute. which means the order_id which i have set as a primary will increase by one. is there any solution to stop the user from pressing refresh or should i write this query somewhere else?

after executing this query to the table called ordering, i then will move all the items in temp_cart table to orderlist table. it will get the order_id from the query "ordering table" above. and delete the item in temp_cart after storing them.

so when i press refresh in the browser F5, the sentence in the screen showing "your order is 3". when i press again, it shows "your order is 4". but the item purchased was empty. meaning that there is no total item or total price being shown out in the screen. only the order number will keep on increasing. so the ordering table will keep on inserting a new order_id and the same amount of the total, collection_date and purchase_date.

is there any solution?

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.