php - Prevent user to use back button with warning or disable any insert -
i have form in page1.php
directs page2.php
data form in page1.php
inserted database. after successful insertion, page2.php
displays message , gives link go third page.
the problem when user after insertion hits button of browser , clicks form submit button, insertion made again.
is there way after 1 insertion when button pressed message displayed showing visiting back-button not allowed? or in case allowed no insertion take place on clicking form submit button?
edited later add part:
okk let me tell in details. admin end. admin gives description text input different products. gives input page1.php , message shown on page2.php description has been inserted db. there form below message. asks whether admin wishes more description text. if yes, clicking on form submit button , taken page across page(s) again taken page1.php ( time product), there page2.php , on. btw use normal page link instead of form button link below message on page2.php
the problem is, while admin on page2.php , hits button , goes page1.php , there if hits on form submit button, data inserted second time in new row.
u may suggest use 'ignore' 'insert' command, there other columns in row may not matched of column while description columns(admin inserts text data column ) may matched.
1)is ignore applicable in case?
2)what should solution if duplicate entry allowed database of site?
thanks
hope makes whole thing clear.
instead of giving link third page, redirect same uri
quite handy method called post/redirect/get:
here concise example of it:
<?php if ($_server['request_method']=='post') { $err = array(); //performing validations , raising corresponding errors if (empty($_post['name'])) $err[] = "username field required"; if (empty($_post['text'])) $err[] = "comments field required"; if (!$err) { //if no errors - saving data , redirect header("location: ".$_server['php_self']); exit; } else { // field values should escaped according html standard foreach ($_post $key => $val) { $form[$key] = htmlspecialchars($val); } } } else { $form['name'] = $form['comments'] = ''; } include 'form.tpl.php'; ?>
here can see example, concise yet powerful: separating logic/style in php properly
it's complete solution display, add , edit database contents, admin purpose.
Comments
Post a Comment