I'm having a strange problem with my php/mysql code, the problem being that when I INSERT my data, it posts it twice...sorta. It will go through once without problems but then it will attempt to insert again. The second time, all the data goes through except for the "author" and "comment" fields.
My code:
$parent = $_POST["parent"];
$date = strip_tags(date("[ Y F d::l - H:i:s ]"));
if($_POST["author"] == "")
{
$author = "anonymous";
}
else
{
$author = strip_tags($_POST["author"]);
}
$comment = str_replace("\n", "<br />", $_POST["comment"]); //replaces the invisible newlines from form into visible html breaks
$comment = eregi_replace("(<hr[^>]*)>", "\\1 />", $comment);
$comment = strip_tags($comment, "<b><i><a><hr><br>");
include("config.php");
$connection = mysql_connect($host, $user, $password);
if($connection)
{
$selection = mysql_select_db($database, $connection);
if($selection)
{
//echo "<br>"; //adding this in will fix the problem...i don't know why
$result = mysql_query("INSERT INTO negative_comments
VALUES (NULL, '$parent', '$date', '$author', '$comment', '$_SERVER[REMOTE_ADDR]')");
if($result)
{
echo "Successful comment.";
}
else
{
echo "Unsuccessful comment.";
}
}
else
{
echo "Database cannot be selected.<br><br>";
echo "Database is permissions locked or does not exist.";
}
}
else
{
echo "Cannot connect to server.";
}
I should point out 2 things:
1) if I put in that "echo" statement before the mysql_query, the code works the way it's suppose to. I don't know why it fixes it.
2) this code doesn't work properly on my Firefox but on my IE, the code works fine with or without the "echo."
Granted, I could just leave in the "echo" but I'd much rather know why it fixes things.
Any help would be greatly appreciated.