I have a form that sends information to another page. This page handles the form data by inserting a row into the database and returning a success/error message depending on success/failure.
The problem is that the data gets written to the table, but two additional rows also get written, where everything is blank except for the date, time and IP fields.
I have been troubleshooting this all night and can't seem to pin-point the problem. If I tell the script to exit() immediately after the query is sent, only one row is written. If I send the exit() further down the page, even before any other PHP is executed, I get the blank rows again.
When I tested it in another browser (Konqueror) I only got one extra row instead of two. This makes me wonder if it is a browser issue and not a scripting issue. The site's using sessions with the IE6 fix:
session_start();
header("Cache-control: private"); //IE 6 Fix
But that's never hurt anything before. Weird...if I comment out the session code I get three extra rows using Firefox as opposed to two.
Using: PHP5, Apache 2, MySQL, Firefox 1.5
Here is the code snippet for the database operation (very simple!):
// Gather comment date
$name = strip_tags(addslashes($_POST['comment-name']));
$email = strip_tags(addslashes($_POST['comment-email']));
$comment_entry = strip_tags(addslashes($_POST['comment-entry']));
$blog_id = $_POST['blog_id'];
$comment_time = date("H:i:s");
$comment_date = date("Y-m-d");
$ip = $_SERVER['REMOTE_ADDR'];
// Connect to database
require_once($_SERVER['DOCUMENT_ROOT'] . "/includes/database.inc.php");
$link = mysql_connect($dbhost, $dbuser, $dbpass);
mysql_select_db($dbname, $link) or die("Unable to connect to database");
// Send query
$query = "INSERT INTO blog_comments SET blog_id='$blog_id', name='$name', email='$email', comment='$comment_entry', comment_date='$comment_date', comment_time='$comment_time', ip='$ip'";
$result = mysql_query($query);
// Close the database
mysql_close($link);
No clue on this one, and my best friend Google couldn't even help me 🙁
Any ideas? 😕