我做了一些统计数据,我想将它们插入数据库以查看流量统计数据。我主要有 HTML 页面,所以我使用 POST 方法来获取由 PHP 文件发布的统计信息,但它不起作用,没有将统计信息插入到数据库表中。
HTML 代码
<form action="_global/stats/stats.php" method="post">
<input type="hidden" name="stats" value="true" />
</form>
PHP 代码
if (isset($_POST['stats']))
{
$stats = $_POST['stats'];
}
else
{$stats="false";}
if ($stats == "true"){
if(!empty($_SERVER['REQUEST_URI'])){
$url = $_SERVER['REQUEST_URI'];
}else{$url = "";}
if(!empty($_SERVER['REMOTE_ADDR'])){
$user_ip = $_SERVER['REMOTE_ADDR'];
}else{$user_ip = "";}
if(!empty($_SERVER['REMOTE_PORT'])){
$user_port = $_SERVER['REMOTE_PORT'];
}else{$user_port = "";}
if(!empty($_SERVER['SERVER_ADDR'])){
$server_ip = $_SERVER['SERVER_ADDR'];
}else{$server_ip = "";}
if(!empty($_SERVER['SERVER_PORT'])){
$server_port = $_SERVER['SERVER_PORT'];
}else{$server_port = "";}
if(!empty($_SERVER['REQUEST_METHOD'])){
$request_type = mysql_real_escape_string ($_SERVER['REQUEST_METHOD']);
}else{$request_type = "";}
if(!empty($_SERVER['HTTP_USER_AGENT'])){
$browser_type = mysql_real_escape_string ($_SERVER['HTTP_USER_AGENT']);
}else{$browser_type = "";}
mysql_query("INSERT INTO jinendra_statistics.statistics SET url='$url', user_ip='$user_ip', user_port='$user_port', server_ip='$server_ip', server_port='$server_port', request_type='$request_type', browser_type='$browser_type' ");
}
请看看这里出了什么问题,并提出任何可能的方法来做到这一点。
更新
带有这些代码的 PHP 文件正在工作,我在数据库中获取值。但是将它与 HTML 一起使用不会在数据库中插入值。
if(!empty($_SERVER['REQUEST_URI'])){
$url = $_SERVER['REQUEST_URI'];
}else{$url = "";}
if(!empty($_SERVER['REMOTE_ADDR'])){
$user_ip = $_SERVER['REMOTE_ADDR'];
}else{$user_ip = "";}
if(!empty($_SERVER['REMOTE_PORT'])){
$user_port = $_SERVER['REMOTE_PORT'];
}else{$user_port = "";}
if(!empty($_SERVER['SERVER_ADDR'])){
$server_ip = $_SERVER['SERVER_ADDR'];
}else{$server_ip = "";}
if(!empty($_SERVER['SERVER_PORT'])){
$server_port = $_SERVER['SERVER_PORT'];
}else{$server_port = "";}
if(!empty($_SERVER['REQUEST_METHOD'])){
$request_type = mysql_real_escape_string ($_SERVER['REQUEST_METHOD']);
}else{$request_type = "";}
if(!empty($_SERVER['HTTP_USER_AGENT'])){
$browser_type = mysql_real_escape_string ($_SERVER['HTTP_USER_AGENT']);
}else{$browser_type = "";}
mysql_query("INSERT INTO jinendra_statistics.statistics SET url='$url', user_ip='$user_ip', user_port='$user_port', server_ip='$server_ip', server_port='$server_port', request_type='$request_type', browser_type='$browser_type' ");