Confirmation if the specific record was already existed in the mysql database the php code will not continue to save data. On another side, if specific data was not yet inside the database the program will execute to save a data.
code to paste:
<html>
<body>
<?php
$con = mysql_connect("localhost","root","yourpassword");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("personalinfo", $con);
$search=$_POST['idno'];
$result = mysql_query("SELECT * FROM marina where idno='$search'");
$count=mysql_num_rows($result);
if($count==1)
{
echo "marina number already exist";
}
else
{
$sql="INSERT INTO table1 (idno, name, address, city, state, zipcode)
VALUES
('$_POST[idno]','$_POST[name]','$_POST[address]','$_POST[city]','$_POST['state']','$_POST[zipcode]')";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo "1 record added";
}
mysql_close($con)
?>
</body>
</html>
No comments:
Post a Comment