troubleshooting Question

storing REMOTE_ADDR and HTTP_USER_AGENT in mysql db at runtime

Avatar of manu009
manu009 asked on
1 Comment1 Solution795 ViewsLast Modified:
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.

Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 1 Comment.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 1 Comment.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros