I am trying to insert the current time()
and $_SERVER['REMOTE_ADDR'];
into my database
I have this code
<?php
require_once("../core/core.php");
$user_time = time();
$ip = $_SERVER['REMOTE_ADDR'];
$sql = "SELECT * FROM userinfo WHERE ip = $ip";
$result = $conn->query($sql);
if(!$result) {
trigger_error('Wrong SQL: ' . $sql . ' Error: ' . $conn->error, E_USER_ERROR); <-- line 10
echo "Database connection failed.";
} else {
if($result->num_rows == 0){
trigger_error('Wrong SQL: ' . $sql . ' Error: ' . $conn->error, E_USER_ERROR);
$sql = "INSERT INTO userinfo (ip, time) VALUES ('$ip', '$user_time')";
$conn->query($sql);
echo "IP ADDRESS SAVED successfully";
} else if($result->num_rows >= 1) {
$sql = "UPDATE userinfo SET time = '$user_time' WHERE `ip` = '$ip'";
$conn->query($sql);
echo "IP ADDRESS UPDATED successfully";
}
}
?>
But i get an error Fatal error: Wrong SQL: SELECT * FROM userinfo WHERE ip = my_real_ip Error: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '.103.25' at line 1 in /home/appunloc/domain/folder/index.php on line 10