PHP and MySQL - sending double records
I am trying to submit a form with two fields (name and email) to a MySQL table.
On a local server (my laptop) it works fine.
But on production server it is published twice!
I can't figure out why.
Here is the code:
$name = ucwords(strtolower(trim($_POST['name'])));
$email = strtolower(trim($_POST['email']));
$mysqli = new mysqli($server, $serveruser, $serverpass, $dbname);
$name = $mysqli->real_escape_string($name);
$email = $mysqli->real_escape_string($email);
$sql = "INSERT INTO table_name (name, email) VALUES ('" . $name . "', '" . $email .
"')";
$res = mysqli_query($mysqli, $sql);
It drives me crazy.
a source to share
I know it sounds like an obvious thing, but the obvious is usually the last thing we check for some reason ...
Are the files on your laptop and the server the same? Maybe you are executing a similar SQL query somewhere else, causing a double entry?
If you comment out the line containing (what you think is the only) SQL query, is anything being injected into the database? If so, you have a second SQL query elsewhere.
Is the file that contains this code that is included in another file using the require or include functions ? If so, is the require_once or include_once function better ?
While these other fixes may work, they are patches - removing the symptom, not fixing the cause. It is better to understand at the deepest level you can find it, rather than just bypass this unexpected behavior.
a source to share