Jump to content

Strange PHP behavior - code mis-counts cumulative data entry in table


artworthy

Recommended Posts

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.

@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?

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.