我有一个名为files的表,其中有id、名称、网页、访问者等列。表中已有文件列表。现在,我已经创建了名为webpage和visitors的新列。网页是文件的URI,访问者是文件的计数器视图。问题是我想用session自动更新网页和访客,但我不能。你能帮我吗?
<?php
session_start();
include_once"config.php";
$webpage=htmlspecialchars($_SERVER["REQUEST_URI"]);
$result=mysql_query("SELECT * FROM files WHERE webpage='$webpage'");
$num_rows = mysql_num_rows($result);
if ($num_rows == 0){
mysql_query("How to update the URI ($webpage) automatically? in the files table inside the column webpage");
}else{
if (!isset($_SESSION['webpage'])){$_SESSION['webpage'] = 0;
mysql_query("UPDATE files SET visitors=visitors+1 WHERE webpage='$webpage'");}}
?>发布于 2014-03-19 20:30:45
尝试此解决方案:
<?php
session_start();
include_once"config.php";
$webpage=htmlspecialchars($_SERVER["REQUEST_URI"]);
$result=mysql_query("SELECT * FROM files WHERE webpage='$webpage'");
$num_rows = mysql_num_rows($result);
if ($num_rows == 0)
{
$_SESSION['webpage'][] = $webpage;
mysql_query("INSERT INTO files (`id`,`name`,`webpage`,`visitors`) VALUES (null,'$name','$webpage','1')");
}
else
{
if(is_array($_SESSION['webpage'])) && !in_array($webpage, $_SESSION['webpage'])))
{
$_SESSION['webpage'][] = $webpage;
mysql_query("UPDATE files SET visitors=visitors+1 WHERE webpage='$webpage'");
}
}
?>https://stackoverflow.com/questions/22504989
复制相似问题