...

View Full Version : Posting 2 times instead of once...



Ludatha
03-09-2008, 04:09 PM
Hi, I have problem, when a user comments on another user's profile it posts 2 comments and adds 2 to the comment count.


function sign()
{
// Sign the guestbook
require_once("classes/DbConnector.php");
$username = $_GET["sign"];
$from = $_GET["from"];
$message = $_POST["message"];
$time = date("F j, Y, g:i a");
$db = new DbConnector();
$db->connect();
$query = "INSERT INTO guestbook(owner,postedby,post,time) VALUES('$username','$from','$message','$time')";
$db->query($query);
echo "<p>Your message has been posted</p>";

// Hit Counter Script
$member = $_SESSION["username"];
require_once("classes/DbConnector.php");
$db = new DbConnector();
$db->connect();
$query = "UPDATE members SET commentCount = commentCount +1 WHERE username='$member'";
$result = $db->query($query);
}

Anyone know what to do to make it post the comment once and add 1 to the counter?

This also happens to my hit counter for the user's page views.


// Hit Counter Script
$member = $_GET["id"];
require_once("classes/DbConnector.php");
$db = new DbConnector();
$db->connect();
$query = "UPDATE members SET hits = hits +1 WHERE username='$member'";
$result = $db->query($query);

mlseim
03-10-2008, 01:07 AM
Without seeing your website, I would guess
that since both things are in the same function,
that function is called twice?

Each time the page is viewed it runs both the
function, which does both things?

Separate them.

Ludatha
03-10-2008, 05:00 PM
No functions are called twice, I found what is causing it sort of, but I don't see why.

In IE7 it works fine, the counter goes up by one (talking about the hit counter)
In Firefox the count goes up by 2 each time the page is loaded...

I have fixed the guestbook posting twice bug.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum