gpt4 book ai didi

php - 使用php在数据库中存储点击次数

转载 作者:行者123 更新时间:2023-11-30 23:25:55 25 4
gpt4 key购买 nike

I am working on a project which includes image gallery.Now I want to store number of clicks/counts value into my database(developed in MySQL). I tried to do it in my own way, but problem is count/clicks value for all the images are stored in the database as same value.

The code given below is in the file main.php which displays images that is retrieved from database.The picture.php is the one that retrieves images from database. I have appended the code to count the number of clicks in picture.php so that it counts whenever the image is clicked.

ma​​in.php

    $query="SELECT * FROM files";
$result=mysql_query($query) or die(mysql_error());
while($fetch=mysql_fetch_array($result)){
echo "<div class=single>
<div class=wrap>
<a href=picture.php?fid=".$offer_id.">
<img src=picture.php?fid=".$offer_id."\">
</a>
</div>
</div>";
}

picture.php

    if(isset($_GET['fid']))
{
include "connect.php";
$fid=$_GET['fid'];
$query="SELECT * FROM offers_em WHERE o_id =$fid";
$result=mysql_query($query) or die(mysql_error());

$sql="UPDATE offers_em SET count+=1 WHERE o_id=".$fid;
$sql2=mysql_query($sql);

$name=mysql_result($result,0,"pic_name");
$size=mysql_result($result,0,"size");
$type=mysql_result($result,0,"type");
$content=mysql_result($result,0,"content");

header("Content-Disposition: attachment; filename=$name");
header("Content-length: $size");
header("Content-type: $type");
echo $content;
}
else{
die("No file ID given...");
}

最佳答案

我不确定MySQL是否支持“+=”,试试SET 计数 = 计数 + 1

编辑:无论如何,一定要考虑对注入(inject)漏洞进行分类,如您帖子下方的评论中所述。

关于php - 使用php在数据库中存储点击次数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13358601/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com