/    Sign up×
Community /Pin to ProfileBookmark

POSTDATA – page Refreshing

hello again..

i need some advice about problem described below.

so:

i have form where i enter some text

[i]here is the form[/i]

[code]<form action=”index.php?p=itm1″ method=”post”>
<table height=”100″ border=”0″ cellpadding=”0″ cellspacing=”0″>
<TR><TD colspan=”3″><i>some text</i></TD></TR>
<TR>
<TD align=”center”>enter new name&nbsp;:&nbsp;</TD>
<TD align=”center”><input type=”text” name=”item”></TD>
<TD align=”center”><input type=”submit” value=”add”></TD>
</TR>
</table>
</form>[/code]

after this text inserted into form as u see is sent to php file called itm1.php

[i]here is the code of that page[/i]

[code]<?php
include(“includes/vars.php”);

$item = $_POST[‘item’];

if ($_POST[‘item’]=$item)

{

mysql_connect(“$hostname”, “$username”, “$password”) or die(mysql_error());
mysql_select_db(“$db”) or die(mysql_error());
mysql_query(“CREATE TABLE IF NOT EXISTS menu(
id INT NOT NULL AUTO_INCREMENT,
PRIMARY KEY(id),
item VARCHAR(300)) “) or die(mysql_error());
mysql_query(“INSERT INTO menu (item)
VALUES(‘$item’)”) or die(mysql_error());

print “<br />”;
echo “&nbsp;&nbsp;new item named <b>$item</b> has been added”;
print “<br />”;
}

else

{

echo “error.. error description”;

}

?>[/code]

if “if” statmant is true it adds new item to db and echos “new item has been added” so everything goes fine.. but

when i refresh the page post data is added to database again..

how can i avoid this? i want if someone refreshes the page … to do something else but not to add the same item again to database.

thanks

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@felgallNov 16.2007 — You need to test if the data is a duplicate of the last entry that was added before allowing it to be added again.
Copy linkTweet thisAlerts:
@LogicOpinionauthorNov 17.2007 — Could you give (show) me some example of testing that ?

thanks
×

Success!

Help @LogicOpinion 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 5.27,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

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