I am running an insert query that should insert one row. However, it runs the query twice, and I can't figure out why.
Prior to the code below, the page runs a select query to get data about an image to be shown on the page. If it gets a result, it creates the html to display the image. After that, it inserts a record into a different table to record that the image has been shown. See below.
$imgid = $intimgid
$sitecode = $strcode;
$viewdate = date('Y-m-d');
$viewtime = date('H:i:s');
$viewip = $_SERVER['REMOTE_ADDR'];
$viewagent = $_SERVER['HTTP_USER_AGENT'];
$statement = '';
$statement = "INSERT INTO table1 (field1, field2, field3, field4, field5, field6) VALUES ('".$imgid."', '".$viewdate."', '".$viewtime."', '".$sitecode."', '".$viewip."', '".$viewagent."')";
$mysqli = new mysqli($dbserver, $dbuser, $dbpass, $dbname);
if ($mysqli->connect_error) {
trigger_error('Database connection failed: ' . $mysqli->connect_error, E_USER_ERROR);
}
$res = $mysqli->query($statement);
mysqli_close($mysqli);
When the query above runs, it inserts two rows. It has to be running twice because I've seen where the seconds in the time field are different by one second. I just can't figure out what's causing it to run twice.