I have this code below and it works fine except when I refresh the page it inserts a blank row. Does anyone know what I need to do here?
<?php
$con=mysqli_connect("localhost","name","password","inventory");
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
// escape variables for security
$inv_number = mysqli_real_escape_string($con, $_POST['inv_number']);
$date = mysqli_real_escape_string($con, $_POST['date']);
$date_type = mysqli_real_escape_string($con, $_POST['date_type']);
$item1 = mysqli_real_escape_string($con, $_POST['item1']);
$location1 = mysqli_real_escape_string($con, $_POST['location1']);
$sql="INSERT INTO invoice (inv_number, date, date_type, item1, location1)
VALUES ('$inv_number', '$date', '$date_type', '$item1', '$location1')";
if (!mysqli_query($con,$sql)) {
die('Error: ' . mysqli_error($con));
}
echo 'Invoice #'.$_POST['inv_number'].' recorded';
mysqli_close($con);
?>
I tried finding conditional if statements that can keep the code from creating blank rows but to no avail have I found a working solution.
Any help is appreciated.