on refresh previous values get submitted
Posted: Mon Mar 09, 2009 1:19 am
Hi,
when i refresh the php page it asks me to resend. If i click resend it takes previously submitted values again. Is there any way to skip this?
when i refresh the php page it asks me to resend. If i click resend it takes previously submitted values again. Is there any way to skip this?
Code: Select all
<?
// Connect database
mysql_connect("localhost","root","");
mysql_select_db("ItcPolicy");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Add Policy</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<h3 align="center">Add Policy Name and File Name:<br />
</h3>
<form action="ListofPolicies.php" method="POST"
enctype="multipart/form-data" name="PolicyForm"
onsubmit="return validate_form(this)">
<table width="60%" border="0" cellspacing="0"
cellpadding="0" align="center">
<tr>
<td width="16%">Policy Name:</td>
<td width="84%"><input name="PolicyName" type="text" size="40" /></td>
</tr>
<tr>
<td> </td><td> </td>
</tr>
<tr>
<td>File Upload: </td>
<td><input type="file" name="file" size="49" /></td>
</tr>
<tr>
<td> </td> <td> </td>
</tr>
<tr>
<td colspan="2" align="left"><input name="Submit" type="submit" value="Add Policy" /></td>
</tr>
</table> </form>
<br><br>
<table width="50%" cellspacing="0"
cellpadding="0" align="center" class="list-tbl">
<tr><th><b>List Of Policies:</b><br></th></tr>
<tr> <td>
<form id="form1" name="form1" method="POST" action="ListofPolicies.php">
<select name="select" multiple>
<option value="">--- Select ---</option>
<?
$q1=mysql_query("SELECT PolicyName, FileName FROM listofpolicies;");
// Show records by while loop.
while($q1arr = mysql_fetch_assoc($q1)){
?>
<option value="<? echo $q1arr['FileName']; ?>" <? if($q1arr['FileName'] == $select){ echo "selected"; } ?>><? echo $q1arr['PolicyName']; ?></option>
<?
// End while loop.
}
?>
</select>
<input type="submit" name="Delete" value="Delete" />
</form></td></tr></table>
<br><br>
</body>
</html>
<?php //delete policy
$select=$_POST['select'];
if($_POST['Delete']!=NULL && $select){
// Get records from database.
mysql_query("DELETE FROM listofpolicies where FileName='$select';");
echo $select." is deleted.";
}
?>
<?php //add policy
$PolicyName = $_POST['PolicyName'];
$Submit = $_POST['Submit'];
$file = $_FILES["file"]["name"];
//if Policy name and File not entered
if($Submit)
{
if($PolicyName == null && $_FILES["file"]["name"] == null)
{
echo "<span style=\"color:#FF0000\">Please Enter Policy Name and File to add new policy.</span><br>";
die;
}
//if file not entered
if($PolicyName != null && $_FILES["file"]["name"] == null)
{
echo "<span style=\"color:#FF0000\">Please Enter File to add new policy.</span><br>";
die;
}
//if Policy name not entered
if($PolicyName == null && $_FILES["file"]["name"] != null)
{
echo "<span style=\"color:#FF0000\">Please Enter Policy Name to add new policy.</span><br>";
die;
}
}
//check the uploaded file and save it pdf folder
if($Submit && $_FILES["file"]["name"] && $PolicyName){
if ($_FILES["file"]["error"] > 0)
{
echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
}
else
{
if (file_exists("pdf/" . $_FILES["file"]["name"]))
{
echo $_FILES["file"]["name"] . "<span style=\"color:#FF0000\"> already exists.</span> ";
die;
}
else
{
move_uploaded_file($_FILES["file"]["tmp_name"],
"pdf/" . $_FILES["file"]["name"]);
}
}
// insert Policy name and file name into db
$q2=mysql_query("INSERT INTO listofpolicies (PolicyName, FileName)
VALUES ('$_POST[PolicyName]', '$file')");
echo $_FILES["file"]["name"] ." is uploaded.";
$_FILES["file"]["name"] = null;
}
?>