Reputation: 3
I have a form that, onsubmit, inserts the data into a table in my database. It works fine except that it inserts two instances of data instead of one. The first instance contains all the info from the form. The second instance contains blank info. My javascript validation is working fine. Here is a trimmed down version of my code after connection :
// escape variables for security
$fname = mysqli_real_escape_string($con, $_POST['fname']);
$lname = mysqli_real_escape_string($con, $_POST['lname']);
$sql="INSERT INTO Persons (fname, lname) VALUES ('$fname', '$lname')";
if (!mysqli_query($con,$sql)) {
die('Error: ' . mysqli_error($con));
}
mysqli_close($con);
?>
When I check my table in phpmyadmin, it contains 2 records, populated data and blank rows. Any thoughts?
Upvotes: 0
Views: 109
Reputation: 75
using <img src="" width="some number" height="some number">
to force a blank table cell in HTML causes a similar problem with Apache and MySQL.
Upvotes: 0
Reputation: 75
The variable $fname is declared twice, consequently overwriting itself. Thus the blank second instance.
Upvotes: 1