Hello all
I have a page in php that INSERTs data in a database via a query. My problem is that when you refresh the page the data is INSERTed again. How can I stop this.
Thanks in advance
Hello all
I have a page in php that INSERTs data in a database via a query. My problem is that when you refresh the page the data is INSERTed again. How can I stop this.
Thanks in advance
hi,
how is the data getting to that page (post or get)
how are your refreshing the page?
After inserting redirect to another page which have link to insert page
That is page home.php have link to insert.php if one click link it takes him to insert.php and after inserting redirect to home.php
could you post the code please?
It seems like you may be using a session?
data is getting to the new page via post. if the user hits the refresh button on his/her browser the data is entered in twice.
<?php
include 'connect.php';
$id=$_POST['id'];
if(!isset($id))
{
echo "<script>alert('eMop ID not Set')</script>";
}
$chkbox = $_POST['chk'];
$imp=$_POST['imp'];
$step= $_POST['step'];
$start=$_POST['start'];
$finish = $_POST['finish'];
$duration = $_POST['dur'];
$status= $_POST['status'];
if(isset($imp)){
foreach($imp as $a => $b){
$query_all = "INSERT INTO test (emop_id, implementor, steps, start, finish, duration, status) VALUES ('$id', '$imp[$a]','$step[$a]','$start[$a]','$finish[$a]','$duration[$a]', '$status[$a]')";
mysql_query($query_all) or die('Error with TEST query, query failed:'. mysql_error());
}
}
Add redirection after inserting
if(isset($imp)){
foreach($imp as $a => $b){
$query_all = "INSERT INTO test (emop_id, implementor, steps, start, finish, duration, status) VALUES ('$id', '$imp[$a]','$step[$a]','$start[$a]','$finish[$a]','$duration[$a]', '$status[$a]')";
mysql_query($query_all) or die('Error with TEST query, query failed:'. mysql_error());
}
header(Location:"home.php");//do redirection here
}
What is i write a SELECT query also. could i still pass data to home or another page using header(Location:"home.php"); ?
you can still pass values using the url in redirect.
however you can simply use sessions like:
if (!isset($_SESSION['form'])){
//handle your form
$_SESSION['form'] = '';
}
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.