Query with ip address produces error

I’m doing a hit counter. I used VARCHAR as database field type. Inserting new record is not a problem but when I query to retrieve record, error occurs.

The error is wrong syntax.

Here is my query.

"SELECT page_visited FROM hit_counter WHERE ip = {$ip}"


$ip= 118.68.189.173

All string type values must be enclosed in single quotes in SQL.

SELECT page_visited FROM hit_counter WHERE ip = ‘$ip’

That will fix that. Thanks Dan!