-2

I have a page which is doing an insert. The DB table has a unique column called "order" that auto increments upon adding a new row. I am executing the insert in this way:

$insert = <<<SQL
INSERT INTO `order` (name, email, team, project, startdate, enddate, comment, server) VALUES (?,?,?,?,?,?,?,?);
SQL;
$instat = $mysqli->prepare($insert);
$bind = mysqli_stmt_bind_param($instat, "ssssssss", $name, $email, $team, $project, $timestart, $timeend, $comment, $code);
$exec = mysqli_stmt_execute($instat);
mysqli_stmt_close($instat);
mysqli_close($mysqli);

I am allowing the DB to handle an auto increment of the order column so that it cannot be duplicated. This works just fine, but if I were to hit refresh on the page, it will insert another row with the same data on a new unique order id. How can I prevent another insert upon a page refresh?

Wes
  • 654
  • 9
  • 24

2 Answers2

1

After saving the row, redirect the page to another page with corresponding message . Your flow will be like

  1) $service->saveObject($dataObject);
  2) redirect_to_success page.
Danyal Sandeelo
  • 11,068
  • 6
  • 37
  • 64
0
  1. before every insert - make select query and check
  2. Make insert query with NOT EXIST:

3.Redirect to current page after insert.

Community
  • 1
  • 1
Kristiyan
  • 1,637
  • 13
  • 17