This question already has an answer here:
I am trying to INSERT data into a database from a PHP form. I have written the code below but I do not understand why everytime I refresh the form it adds a new row with the previously entered data into my Database. If someone could help me fix this issue, please.
<! DOCTYPE html>
<html>
<head>
<style>
.error {color: #FF0000;}
</style>
</head>
<body>
<?php include 'config.php'; ?>
<?php
if(isset($_POST['submit'])) {
$fname = $_POST['fname'];
$lname = $_POST['lname'];
$addr = $_POST['addr'];
$phone = $_POST['phone'];
$query = "INSERT INTO `employee`(fname,lname,addr,phone) VALUES ('$fname','$lname','$addr','$phone')";
$result = mysqli_query($con,$query) or die ("problem inserting new product into database");
}
?>
<h2>Sign Up</h2>
<h3>Enter the data to Sign Up</h3>
<p><span class="error">* required field</span></p>
<form action = "" method = "post">
Name: <input type = "text" name = "fname">
<span class=error>*</span><br>
Surname: <input type="text" name="lname">
<span class=error>*</span><br>
Address: <input type = "text" name = "addr">
<span class=error>*</span><br>
Phone Number: <input type = "tel" name="phone"><br>
<input type = "submit" name="submit" value="Submit">
</form>
</body>
</html>
</div>