Duplicate Data
Posted: Tue Nov 18, 2008 6:33 am
Hi All
Can someone please point out to me what is wrong with this code? Each time I refresh the page it inserts duplicate data in database. Other than that it doesn't give out any errors. Some help will be greatly appreciated.
Thanks
Zed
Can someone please point out to me what is wrong with this code? Each time I refresh the page it inserts duplicate data in database. Other than that it doesn't give out any errors. Some help will be greatly appreciated.
Code: Select all
<?
include("config.php");
function insert(){
$id = $_POST['id'];
$news = $_POST['news'];
if(empty($news)) error_message("You need to enter some text in news box!");
$query = "INSERT INTO news VALUES
(NULL,'$news')";
$result = mysql_query($query)or die(mysql_error());
if (@mysql_query($query)) {
echo '<p>Your Fresh news have been added. </p>';
} else {
echo '<p>Error adding submitted Information: ' .
mysql_error() . '</p>';
}
}
function form(){
?>
<center><h1>Add News</h1>
<form name="action" id="action" method="post" action="<?=$_SERVER['PHP_SELF']?>">
<table width="60%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="18%"></td>
<td width="82%"><input name="f_id" type="hidden" value="" /></td>
</tr>
<tr>
<td></td>
<td>Add fresh news here and click 'Submit' button</td>
</tr>
<tr>
<td> </td>
<td><textarea name="news" cols="55" rows="15"> </textarea></td>
</tr>
<tr>
<td> </td>
<td><input name="submit" type="submit" value="Submit" />
<input name="reset" type="reset" value="Reset" /></td>
</tr>
</table>
</form></center>
<?
}
if (! isset($_POST['submit'])){
form();
}else{
insert();
}Zed