prevent sql query from running
Moderator: General Moderators
prevent sql query from running
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.
Jcart | Please use
Jcart | Please use
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
} ?>Jcart | Please use
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]
Last edited by rajan on Tue Nov 08, 2005 4:45 pm, edited 6 times in total.
-
Charles256
- DevNet Resident
- Posts: 1375
- Joined: Fri Sep 16, 2005 9:06 pm
-
Charles256
- DevNet Resident
- Posts: 1375
- Joined: Fri Sep 16, 2005 9:06 pm
-
Charles256
- DevNet Resident
- Posts: 1375
- Joined: Fri Sep 16, 2005 9:06 pm
-
Charles256
- DevNet Resident
- Posts: 1375
- Joined: Fri Sep 16, 2005 9:06 pm
- n00b Saibot
- DevNet Resident
- Posts: 1452
- Joined: Fri Dec 24, 2004 2:59 am
- Location: Lucknow, UP, India
- Contact:
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
you take a session variable in which you store the POST status i.e. $_SESION['posted'] = (true or false);
when submitted, set it to true... if already true then don't run the query... simple enough
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
}
}
?>