Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder Ludatha's Avatar
    Join Date
    Jan 2008
    Posts
    250
    Thanks
    51
    Thanked 5 Times in 5 Posts

    Posting 2 times instead of once...

    Hi, I have problem, when a user comments on another user's profile it posts 2 comments and adds 2 to the comment count.

    PHP Code:
    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.
    PHP Code:
    // 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); 

  • #2
    Master Coder mlseim's Avatar
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,386
    Thanks
    8
    Thanked 1,077 Times in 1,068 Posts
    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.

  • #3
    Regular Coder Ludatha's Avatar
    Join Date
    Jan 2008
    Posts
    250
    Thanks
    51
    Thanked 5 Times in 5 Posts
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •