/    Sign up×
Community /Pin to ProfileBookmark

Help to prevent double submit on refresh

Hi all
I have one problem. I have created one little admin panel. and when i submitted a post and i refresh it again it automatically posts the post again. it posts as many as i click refresh. who can help me to eliminate this problem.
here is my problem.

[code=php]<html><head>
<meta http-equiv=”content-type” content=”text/html;charset=utf-8″ />

</head>
<body>
<?php
include(“../config/connect.php”);
include(“../config/resim.php”);
$error = ”;
$seher=$_POST[‘seher’];
$mezmun = $_POST[‘mezmun’];
$subyekt = $_POST[‘subyekt’];
$ish=$_POST[‘place’];
$date=date(‘Y-m-d’);
$no=$_POST[‘no’];
$haber_kucuk_resim_klasor=”../haber_kucuk”; // bu klasorleri acmayi unutmayin
$haber_buyuk_resim_klasor=”../haber_buyuk”; // mutlaka bu iki klasore yazma izni vermelisiniz chmod 777
$buyuk_resim_en=640;
$buyuk_resim_boy=480;
$kucuk_resim_en=200;
$kucuk_resim_boy=150;
if(isset($_POST[‘submit’])) {
if($mezmun == ” || $subyekt == ”) {
$error .= ‘A required field was left blank.<br />’;
echo $error;
return false;
}
if(strlen($_FILES[“resim”][“name”])>4)
{// eger resim varsa bu resmi turkce karakterlerden temizledikten sonra
// resim ve kucukresim olmak uzere iki tane resme donusturecegiz
// echo “resim devrede resim=$resim”;
$bul=$_FILES[“resim”] ;
$bulunacak = array(‘&#1079;’,’&#1047;’,’&#1101;’,’&#1069;’,’&#1088;’,’&#1056;’,’&#1100;’,’&#1094;’,’&#1070;’,’&#1102;’,’&#1062;’,’&#1068;’,’,’,’ ‘,'(‘,’)’,'[‘,’]’);
$degistir = array(‘c’,’C’,’i’,’I’,’g’,’G’,’u’,’o’,’S’,’s’,’O’,’U’,”,’_’,”,”,”,”);
$_FILES[“resim”]=str_replace($bulunacak, $degistir, $bul);
$resim = “$haber_buyuk_resim_klasor/”.$_FILES[“resim”][“name”];
move_uploaded_file($_FILES[“resim”][“tmp_name”],$resim);
$kucukresim = “$haber_kucuk_resim_klasor/”.$_FILES[“resim”][“name”];
move_uploaded_file($_FILES[“resim”][“tmp_name”],$kucukresim);
// kucuk resmi boyutlandiriyoruz
$icerik = resample($resim,$kucuk_resim_en,$kucuk_resim_boy);
$dosya = fopen ($kucukresim,”w+”);
fwrite($dosya,$icerik);
fclose($dosya);
// buyuk resmi boyutlandiriyoruz
$icerik = resample($resim,$buyuk_resim_en,$buyuk_resim_boy);
$dosya = fopen ($resim,”w+”);
fwrite($dosya,$icerik);
fclose($dosya);
// resim boyutlandirma bitti
}
if($error == ”) {
mysql_query(“INSERT INTO jobs VALUES(”,’$seher’, ‘$mezmun’, ‘$ish’,’$subyekt’, ‘$date’,”)”);
$mezmun=false;
$subyekt=false;
$date=false;
}
}
?>
<?
if(isset($_POST[‘duzelt’])){
//$no=$_POST[‘no’];
$sor=mysql_query(“SELECT * FROM jobs where id=’$no'”);
while($res=mysql_fetch_row($sor)){
$no2=$res[0];
$mezmun2=$res[1];
$subyekt2=$res[2];
}
echo $no;
}
?>
<form name=”list” action=”” method=”POST”>

<table width=”100%” class=”mytable” border=””>
<tr bgcolor=#c0c0c0>
<td></td><td>&#350;&#601;h&#601;r</td><td>V&#601;zif&#601;nin adi</td><td>Sah&#601;</td><td>&#304;&#351; yeri</td><td>Qoyulduqu Tarix</td></tr>

<?
if(isset($_POST[‘show’])){
//$no=$_POST[‘no’];
$res=mysql_query(“select * from jobs where sekil=” ORDER BY id DESC”);

function daysDifference($endDate, $beginDate){ //explode the date by “-” and storing to array
$date_parts1=explode(“-“, $beginDate);
$date_parts2=explode(“-“, $endDate); //gregoriantojd() Converts a Gregorian date to Julian Day Count
$start_date=gregoriantojd($date_parts1[1], $date_parts1[2], $date_parts1[0]);
$end_date=gregoriantojd($date_parts2[1], $date_parts2[2], $date_parts2[0]);
return $end_date – $start_date;
}

while($sor=mysql_fetch_row($res)){
$id1=$sor[0];
$seher=$sor[1];
$sahe=$sor[2];
$place=$sor[3];
$vezife=$sor[4];
$date=$sor[5];
$datenow1=date(‘Y-m-d’);
$ferq=(int)daysDifference($datenow1,$date);
if($ferq>1){

echo “<tr class=”row” id=”row1″ onmouseover=”this.className=’highlight’; current_row=1″ onmouseout=”this.className=’row'”>
<td id=”xana0″><input type=”checkbox” id=”checkbox[]” name=”checkbox[]” value=”$id1″><input type=”submit” name=”delete” value=”POZ”></td><td id=”xana0″>”.$seher.”</td><td width=330px id=”xana1″><a href=’#’ class=”li”>”.$vezife.”</a></td><td width=170 id=”xana1″>”.$sahe.”</td><td width=350 id=”xana1″>”.$place.”</td><td id=”xana2″>”.$date.”</td>
</tr>”;
}
else {

echo “<tr class=”row” id=”row1″ onmouseover=”this.className=’highlight’; current_row=1″ onmouseout=”this.className=’row'”>
<td id=”xana0″><input type=”checkbox” id=”checkbox[]” name=”checkbox[]” value=”$id1″ ><input type=”submit” name=”delete” value=”POZ”></td><td id=”xana1″>”.$seher.”</td><td width=330px id=”xana1″><a href=’#’ class=”li”>”.$vezife.”</a></td><td width=170 id=”xana1″>”.$sahe.”</td><td width=350 id=”xana1″>”.$place.”</td><td class=”tarix” id=”xana2″>bu gun</td>
</tr>”;
}

}
}
?>
<?

if(isset($_POST[‘delete’])){

$checkbox=$_POST[‘checkbox’]; //from name=”checkbox[]”
$countCheck=count($_POST[‘checkbox’]);
for($i=0;$i<$countCheck;$i++)
{
$del_id=$checkbox[$i];
echo $del_id;

$sql = “DELETE from jobs where id=$del_id”;
$result = mysql_query($sql);
}
if($result)
{

echo “successful delete”;
}
else
{
echo “Error: “.mysql_error();
}
}

?>

</table>
</form>
<table>
<form name=”enter” action=”” method=”POST” enctype=”multipart/form-data”>
<tr><td>&#350;&#601;h&#601;r:</td><td><select name=”seher” id=”seher”>
<option default value=””></option>
<option name=”Baki” value=”baki”>Baki</option>
<option name=”Sumqay&#305;t” value=”sumqay&#305;t”>Sumqay&#305;t</option>
<option name=”G&#601;nc&#601;” value=”g&#601;nc&#601;”>G&#601;nc&#601;</option>
<option name=”L&#601;nk&#601;ran” value=”l&#601;nk&#601;ran”>L&#601;nk&#601;ran</option>
<option name=”Sabirabad” value=”sabirabad”>Sabirabad</option></select></td></tr>
<tr><td>Vezifenin adi:</td><td> <input type=”text” name=”subyekt” width=”100″ maxlength=”100″ value=”<? echo $subyekt2; ?>”></td></tr>
<tr><td>Sahe: </td><td><input type=”text” name=”mezmun” width=”100″ maxlength=”50″ value=”<? echo $mezmun2; ?>”/></td></tr>

<tr><td>I&#351; yeri:</td><td> <input type=”text” name=”place” width=”100″ maxlength=”100″ value=”<? echo $place2; ?>”></td></tr><br />
<tr><td>Sekil: </td><td><input type=”file” name=”resim” /></td></tr><br/>
<tr><td>News:</td><td> <textarea name=”news” cols=”60″ rows=”6″ class=”Formstyles”></textarea></td></tr>
<tr><td><input class=”Formstyles” name=”submit” type=”submit” value=”Add” onClick=”yoxla();”/>
<input class=”Formstyles” name=”duzelt” type=”submit” value=”deyis” /><td><input class=”Formstyles” name=”show” type=”submit” value=”goster” />
<input class=”Formstyles” name=”delete” id=”delete” type=”submit” value=”poz” /></td></tr></td>
<tr><td>istedyini xeberi sec:</td><td>
<select name=”no” id=”no”>
<OPTION SELECTED VALUE=””>Select…</OPTION>
<?
$sorgu=mysql_query(“SELECT * FROM jobs”);
while($satir=mysql_fetch_array($sorgu))
{
echo “<option value=’$satir[0]’>$satir[1]</option>”;
}
?>
</select></td></tr></table>
</form></body>
</html>[/code]

thanks for attention

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@NogDogDec 19.2010 — One common technique is to do a header() redirect to a "landing page" upon successful completion of the form processing, so that refreshing that landing page does not try to resubmit the form data (much like this forum does when you post a new thread). If you need to output anything specific about the transaction on that page, you can put the info into a session variable and access that on the landing page. (Note that the landing page could still be the same file if you want it to be, but based on what is in the session data and/or the URL query string, it would know what to do.
[code=php]
<?php
// process form data...then:
if($successful) {
// there must be no output of any kind before this line:
header('Location http://www.example.com/landing_page.php?success=1');
exit;
}
else {
// display error message, maybe redisplay form, etc.
}
[/code]
Copy linkTweet thisAlerts:
@azegurbauthorDec 19.2010 — Thank you very much. you helped me
×

Success!

Help @azegurb spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.30,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...