我正在尝试运行图像获取的视图总数。我的测试文件每次都能完美运行。实际文件image_win.php没有,经过多次测试后看不出有什么问题。此文件STRANGENESS:前两个视图计数正常,其中1添加了字段image_visit中的总计。但是每次将2添加到image_visit中的总数之后。非常离奇。
谢谢你看看-Allen
<?
////////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' ");
?>
答案 0 :(得分:1)
您是否检查过您的查询是否成功?裸眼处理应该是:
$res = mysql_query($QUERY) or die(mysql_error());
和
mysql_query("UPDATE userInfo SET image_visit = image_visit +1 WHERE user_id = '$owner_id'") or die(mysql_error());
同样,假设art_id
是artWork
表的主键,那么查询最多只返回1行,因此不需要执行while()
循环以获取查询结果。只需$row = mysql_fetch_array()
,无需循环。
同样,您的代码完全容易受到SQL注入攻击,所以我会指出http://bobby-tables.com来阅读更多相关内容。