When a visitor comes to my website, I want to store REMOTE_ADDR and HTTP_USER_AGENT in mysql db at runtime.
I store them in a variable and then insert those values in a mysql database.
$referer = $_SERVER["HTTP_REFERER"];
$browser = $_SERVER["HTTP_USER_AGENT"];
$ipaddress = $_SERVER["REMOTE_ADDR"];
$query = "INSERT INTO data VALUES ($ipaddress,$browser,$referer)";
When run, the above query throws following error:
You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near '.166.16,Mozilla/5.0 (Windows; U; Windows NT 5.0; en-GB; rv:1.7.
I know that 116.16 is the last part of my own IP address.
Is it like that as the REMOTE_ADDR & HTTP_USER_AGENT return values with some characters that are illegal in mysql?
how do I get away with this problem :-)
Thanks in advance.