I have made some statistics which I want to insert into database to see traffic stats.
I mostly have HTML pages so I used POST method to get statistics posted by a PHP file, but it is not working no stats are inserted into database table.
HTML Codes
<form action="_global/stats/stats.php" method="post">
<input type="hidden" name="stats" value="true" />
</form>
PHP Codes
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' ");
}
Please See what’s going wrong here and suggest any possible way to do it.
Update
PHP file with these codes is working i get values in database. but using it with HTML doesn’t insert values in database.
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' ");
To anyone reading this: There were two issues that were fixed.
1) The query had incorrect syntax, and
2) The process of submitting the form was also incorrect.
You want to use
SETforUPDATEand the syntax I provided forINSERT.this/page.php
Try this out. Enter the name of the file you save this as in the action.