1
I am trying to create a login log of my page, and store this information in the table stat
however I am not succeeding and is not returning any error. I put an IF to signal if the inclusion was made.
My code is like this:
php connection.
<?php
date_default_timezone_set('America/Sao_Paulo');
define('HOST', 'localhost');
define('DB', 'kurmabi');
define('USER', 'root');
define('PASS', '');
$conn = new PDO('mysql:host=' . HOST . ';dbname=' . DB . ';', USER, PASS);
?>
index php.
include_once("libraries/conexao.php");
ini_set('display_errors', true);
error_reporting(E_ALL);
$usuario = 18;
$navegador = $_SERVER['HTTP_USER_AGENT'];
$sessao = session_id();
$meuip = $_SERVER['SERVER_ADDR'];
$origem = $_SERVER['QUERY_STRING'];
$idioma = $_SERVER['HTTP_ACCEPT_LANGUAGE'];
$servidor = $_SERVER['SERVER_SIGNATURE'];
$visitada = $_SERVER['REQUEST_URI'];
$pais = "<span id='country'></span>";
$estado = "<span id='state'></span>";
$cidade = "<span id='city'></span>";
$lat = "<span id='latitude'></span>";
$long = "<span id='longitude'></span>";
$ip = "<span id='ipv4'></span>";
$hora_req = date('H:i:s');
$registro = date('Y-m-d H:i:s');
$sql = "INSERT INTO `stat` (`id_stat`, `navegador`, `ip_visitante`, `sessao`, `pais`, `estado`, `cidade`, `latitude`, `longitude`, `ip_meuservidor`, `hora_req`, `origem`, `idioma`, `servidor`, `visitada`, `registro`) VALUES (NULL, '$navegador', '$ip', '$sessao', '$pais', '$estado', '$cidade', '$lat', '$long', '$meuip', '$hora_req', '$origem', '$idioma', '$servidor', '$visitada', CURRENT_TIMESTAMP)";
$insert = $conn->prepare($sql);
if($insert->execute()){
echo "Yuhuuu!!!";
} else {
echo "Não foi";
}
You need to get the SQL error, the
error_reporting
does not inform it. Tries to give aprint_r($insert->errorInfo());
in theelse
to see the error that returns. -> https://stackoverflow.com/questions/8776344/how-to-view-query-error-in-pdo-php– gustavox
Have you already tested this query directly in the database ? If so, what was the result you got ?
– Isac