prevent sql query from running
Posted: Tue Nov 08, 2005 2:52 pm
when i refresh the page, the sql query on that page also runs. is there any idea to prevent sql query from running when somebody refersh that page.
A community of PHP developers offering assistance, advice, discussion, and friendship.
http://forums.devnetwork.net/
Code: Select all
andCode: Select all
tags where appropriate when posting code. Read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
my account is updated when anybody refresh that page because sql will also run when anybody referesh that pageCode: Select all
<?php
$sql="delete from acinfo where username='$_SESSION[email]'"
$result=mysql_query($sql)or die("database fetch error".mysql_error());
$sql="select * from acinfo where username='$_SESSION[email]'";
$result=mysql_query($sql)or die("database fetch error".mysql_error());
while($row=mysql_fetch_assoc($result))
{
?>
<tr align="center">
<td><? echo $row['accounttype'] ?></td>
<td><? echo $row['purchased'] ?> </td>
<td><? echo $row['used'] ?> </td>
<td><? echo $row['purchased']-$row['used'] ?> </td>
<td><input name="radiobutton" type="radio" value="<? echo $row['accounttype'] ?>" <? if($_POST['radiobutton']==$row['accounttype']){ echo "checked"; }?>></td>
</tr>
<?php
} ?>Code: Select all
andCode: Select all
tags where appropriate when posting code. Read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]pleaseCharles256 wrote:whoa..edit your post and slap that in PHP tags..
COOOL MAN! take it easy!rajan wrote:i am asking about situation not that specific program .
i simply ask how i make a program in which nothing happen when sombody referesh the page
well, it's time to recall what you had read about http methods, especially rfc2616:rajan wrote: i simply ask how i make a program in which nothing happen when sombody referesh the page
so, delete (create/update) user accounts only in response to POST requests. After the action has been completed, redirect user to the page where the information is displayed. Using your example:RFC2616, sec 9 wrote: In particular, the convention has been established that the GET and HEAD methods SHOULD NOT have the significance of taking an action other than retrieval. These methods ought to be considered "safe". This allows user agents to represent other methods, such as POST, PUT and DELETE, in a special way, so that the user is made aware of the fact that a possibly unsafe action is being requested.
Code: Select all
<?php
if(count($_POST)) { // delete action has been requested
$sql="delete from acinfo where username='$_SESSION[email]'"
$result=mysql_query($sql)or die("database fetch error".mysql_error());
header("Location: $_SERVER[PHP_SELF]");
die();
} else {
$sql="select * from acinfo where username='$_SESSION[email]'";
$result=mysql_query($sql)or die("database fetch error".mysql_error());
while($row=mysql_fetch_assoc($result))
{
?>
<tr align="center">
<td><? echo $row['accounttype'] ?></td>
<td><? echo $row['purchased'] ?> </td>
<td><? echo $row['used'] ?> </td>
<td><? echo $row['purchased']-$row['used'] ?> </td>
<td><input name="radiobutton" type="radio" value="<? echo $row['accounttype'] ?>" <? if($_GET['radiobutton']==$row['accounttype']){ echo "checked"; }?>></td>
</tr>
<?php
}
}
?>