I have the below simple code for inserting some failed login values in my database, but I have some problems:
1- The ip address is being saved in the database as zero no success whatever I do (going crazy on this). 2- I used current time stamp to get the date and time in a simple query, now that I use prepared statements it doesnt work with it, I am forced to use date('Y-m-d H:i:s'); which gives out the wrong time.
My code is:
<?php
$username = $_SESSION['Name'];
$ip_address = $_SERVER['REMOTE_ADDR'];
$attempted = date('Y-m-d H:i:s');
$query = "INSERT INTO failed_logins (username, ip_address, attempted) VALUES(?, ?, ?)";
$failed = $conn->prepare($query);
$failed->bindParam(1, $username);
$failed->bindParam(2, $ip_address);
$failed->bindParam(3, $attempted);
$failed->execute();
?>
My ip_address row in the database is int(11) and it is unsigned.
Any suggestions would help thanks
UPDATE:
I did the below but still no luck:
I changed:
$ip_address = $_SERVER['REMOTE_ADDR'];
to this:
$ip_address = ip2long($_SERVER['REMOTE_ADDR']);