Problem with PHP and Mysql integration

Hi Experts,

I am a beginner of PHP and trying to create a tutorial database. My web interface takes a value and inserts into table very correctly. But when I refresh the same interface, it inserts the same value again and again. My code is below:

<?php
$con = mysql_connect("localhost","root","India123");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

// Create database
if (mysql_query("CREATE DATABASE naushad1",$con))
  {
  echo "Database created";
  }
/*else
  {
  echo "Error creating database: " . mysql_error();
  }*/

// Create table
mysql_select_db("naushad1", $con);
$sql = "CREATE TABLE Persons
(
FirstName varchar(15) primary key,
LastName varchar(15),
Age int
)";

// Execute query
mysql_query($sql,$con);

mysql_close($con);
$con = mysql_connect("localhost","root","India123");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("naushad1", $con);

$sql="INSERT INTO Persons (FirstName, LastName, Age)
VALUES
('$_POST[firstname]','$_POST[lastname]','$_POST[age]')";

if (!mysql_query($sql,$con))
  {
  die('Error: ' . mysql_error());
  }
echo "1 record added";

mysql_close($con);

Please help.

Thanks,
Deepak

You will find better help in a MySQL forum.

Of course it does, but it's not an error of MySQL or PHP. When you refresh the page, the browser just sends the same information again, and your table accepts duplicate values. All of this is accepted behaviour, and if you want it different you'll have to change your table to only accept unique values (eg. by using an INDEX), or do the checks with PHP.