Help - Search - Members - Calendar
Full Version: very odd SQL incrementing problem
Weborum Webmaster Forum > Web Page Design > PHP
morrowasted
For some reason my code is incrementing the field by two instead of one blink.gif.
PHP

<?PHP

$id
= $_GET['id'];

$dbh=mysql_connect ("localhost", "codetut_greg", "********") or die ('I cannot connect to the database because: ' . mysql_error());
    if(&
#33;$dbh) { echo "error"; }
        
mysql_select_db ("codetut_main");
$query = "SELECT clicks FROM tutorials WHERE ID = '$id'";
    
$result = mysql_query($query);
$clicks = mysql_fetch_object($result);
$clicks = $clicks->clicks;
echo
$clicks;
    
$sql = "UPDATE tutorials SET clicks = $clicks + 1 WHERE ID = $id";

    
$result2 = mysql_query($sql);
        if(&
#33;$result2) { echo "error on 2nd query"; }

?>


If I put the code in any other page though, it only increments by one. Could it be that the code is on a page with a frameset?
Timo
hmm... I don't really know... So, it's on the page that defines the frames? Try pulling from the database and outputting that new count right after you set it... Or if that's what you've already done...

I'd assume you found your error if that's the only change causing the error... Are you doing this up near the headers? Try doing it there... I don't know if it will change anything but it's always good to check.

-Tim
Josh
I was trying to help him but I couldn't figure it out.

That's essentially what I do with mine.
morrowasted
I was thinking that since the code is inside the frameset, perhaps it was executing twice. I'm gonna try putting the code inside the header frame and see if it still does it.

But not until I get back from colorado smile.gif.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.