Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/82.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何自动更新网页的URI?_Php_Html_Count_Uri - Fatal编程技术网

Php 如何自动更新网页的URI?

Php 如何自动更新网页的URI?,php,html,count,uri,Php,Html,Count,Uri,我有一个名为files的表,其中有id、name、webpage、visitors等列。表中已有文件列表。现在我已经创建了新的专栏,名为“网页和访问者”。网页是文件的URI,访问者是文件的计数器视图。问题是我想用session自动更新网页和访问者,但我不能。你能帮帮我吗 <?php session_start(); include_once"config.php"; $webpage=htmlspecialchars($_SERVER["REQUEST_URI"]); $resu

我有一个名为files的表,其中有id、name、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'");}}

?>
尝试此解决方案:

<?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'");
    }
}
?>

更新URL的具体内容是什么??你能用示例数据解释一下吗?我不确定我是否完全理解你的问题,但作为旁注,我要提到的是,你不应该再使用mysql函数了,因为它们已经被弃用了。请改用mysqli_*或PDO!,代码“mysql_查询”(“插入文件(
id
name
webpage
visitors
)值为空,“$name',$webpage','1');”创建一个新行,我不想这样做。我只想更新上一条记录中的详细信息。我可能会使用UPDATE命令?你能帮我吗?那很好。但当那个时并没有找到网页的记录时,您需要将它也插入数据库$webpage=htmlspecialchars($_SERVER[“REQUEST_URI”])$result=mysql_查询(“从文件中选择*,其中网页=“$webpage”)$num_rows=mysql_num_rows($result);if($num_rows==0){mysql_query(“更新文件集id=id,其中webpage='$webpage'));我尝试了类似的方法,但不起作用,但当我命令插入代码时,文件将出现重复列,即,将插入一个新列,其中将有新id、网页和访问者。如果我能够在以前的记录中更新网页URI,则这将更容易。