artworthy Posted May 24, 2011 Share Posted May 24, 2011 I'm trying to have a running total of the number of views an image gets. My test file works perfectly every time. The actual file, image_win.php, does not and after much testing can't see what's wrong. This files STRANGENESS: the first two views count fine, with 1 added the total in the field image_visit. But every time after that 2 is added to the total in image_visit. Very bizarre. Thanks for taking a look -Allen <?php ////////TEST IMAGE_WIN //////////THIS WORKS include_once "scripts/connect_to_mysql.php"; include_once "scripts/paths.php"; $art_id = 372; $QUERY="SELECT user_id FROM artWork WHERE art_id = '$art_id'"; $res = mysql_query($QUERY); $num = mysql_num_rows($res); if($num >0){ while($row = mysql_fetch_array($res)){ $owner_id = $row['user_id']; } } mysql_query("UPDATE userInfo SET image_visit = image_visit +1 WHERE user_id = '$owner_id'"); ?> <?php //////// image_win.php /////////THIS DOES NOT WORK $user_id=$_SESSION['user_id']; include_once "scripts/connect_to_mysql.php"; include_once "scripts/paths.php"; $image_link = $_GET['image_link']; $art_id = $_GET['art_id']; ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta name="viewport" content="width=device-width, height=device-height, target-densityDpi=device-dpi"> <title>Image Window</title> </head> <body bgcolor="#000000" leftmargin="0"> <div align="center" > <img src="slir/w640-h535/<?php echo $path.$image_link.$postCat; ?>" /> <?php $QUERY="SELECT user_id FROM artWork WHERE art_id = '$art_id'"; $res = mysql_query($QUERY); $num = mysql_num_rows($res); if($num >0){ while($row = mysql_fetch_array($res)){ $owner_id = $row['user_id']; } } mysql_query("UPDATE userInfo SET image_visit = (image_visit +1) WHERE user_id = '$owner_id' "); ?> MOD EDIT: code tags added. Quote Link to comment https://forums.phpfreaks.com/topic/237373-strange-php-behavior-code-mis-counts-cumulative-data-entry-in-table/ Share on other sites More sharing options...
Pikachu2000 Posted May 24, 2011 Share Posted May 24, 2011 When posting code, enclose it within the forum's . . . BBCode tags. Quote Link to comment https://forums.phpfreaks.com/topic/237373-strange-php-behavior-code-mis-counts-cumulative-data-entry-in-table/#findComment-1219787 Share on other sites More sharing options...
xyph Posted May 24, 2011 Share Posted May 24, 2011 You aren't checking for MySQL errors. Look for obvious issues before asking for help please Quote Link to comment https://forums.phpfreaks.com/topic/237373-strange-php-behavior-code-mis-counts-cumulative-data-entry-in-table/#findComment-1219790 Share on other sites More sharing options...
artworthy Posted May 25, 2011 Author Share Posted May 25, 2011 @xyph There are no mysql errors. As stated I get values every time. In the test file the values updated are always correct. In the image_win.php file values are updated but inconsistently. Are there any non-snarky members out there who are curious why this is happening? Quote Link to comment https://forums.phpfreaks.com/topic/237373-strange-php-behavior-code-mis-counts-cumulative-data-entry-in-table/#findComment-1219827 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.