am having a small problem with my php-mysql connectivity. am entering values in a form and retrieving them in a atabase.But if i go on the refresh link the previous values gets added again.
the code is below:
<html>
<head>
<title>
this is a program
</title>
</head>
<body>
<form method="post">
<input type="hidden" name="act" value="add"/>
<table width="700" border="0" cellpadding="2" cellspacing="1" align="center">
<tr>
<td width="100">Title</td>
<td><input name="title" type="text"></td>
</tr>
<tr>
<td width="100">Content</td>
<td><textarea name="content" cols="50" rows="10"></textarea></td>
</tr>
<tr>
<td width="100"> </td>
<td> </td>
</tr>
<tr>
<td colspan="2" align="center"><input name="save" type="submit" value="Save Article"></td>
</tr>
</table>
</form>
<?php
//unset($_POST["act"]);
if($_POST["title"]=="")
{
echo "Please enter a title";
exit();
}
if($_POST["act"]=="add")
{
echo $_POST["act"];
$username="root";
$password="";
$host="localhost";
/*$fd=*/mysql_connect($host,$username,$password) or die("Error connecting to MySQL");
$dbname='cms2';
@mysql_select_db($dbname) or die("Unable to select database");
$field1=$_POST["title"];
$field2=$_POST["content"];
$field3=$_POST["act"];
/* $field4=$_POST["Headline"];
$field5=$_POST["Article"];*/
unset($_POST);
$query="CREATE TABLE cmstable(id int (6) NOT NULL auto_increment,title varchar(15) NOT NULL,content varchar(100) NOT NULL,act varchar(20) NOT NULL,PRIMARY KEY(id), UNIQUE id (id),KEY id_2 (id))";
mysql_query($query);
$query="INSERT into cmstable VALUES('','$field1','$field2','$field3')";
mysql_query($query);
mysql_close();
exit();
}
?>