Here is my code of PHP
<?php
/* Attempt MySQL server connection. Assuming you are running MySQLServer with default setting (user 'root' with no password) */
$link = mysqli_connect("localhost", "root", "", "login");
// Check connection
if($link === false){
die("ERROR: Could not connect. " . mysqli_connect_error());
}
// Escape user inputs for security
$fname = mysqli_real_escape_string($link, $_POST['fname']);
$lname = mysqli_real_escape_string($link, $_POST['lname']);
$address = mysqli_real_escape_string($link, $_POST['address']);
$phone = mysqli_real_escape_string($link, $_POST['phone']);
// attempt insert query execution
$sql = "INSERT INTO persons (firstname, lastname, address, phone) VALUES ('$fname', '$lname', '$address', '$phone')";
if(mysqli_query($link, $sql))
{
echo "Records added successfully.";
}
else
{
echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
}
// close connection
mysqli_close($link);
?>
This code is running fine but after refreshing the form it automatically submitted the old data on the database. Please help me to resolve the issue.