I have a MySQL table containing columns for user IP (IP) and their name (Name). I want to compare the user’s browser IP to the IP column the SQL table, and save their name to a PHP variable $name should an IP match be found.
I’m using $ip = $_SERVER['REMOTE_ADDR'] to save the browser’s IP. How would I go about comparing this variable to the IP addresses in the SQL database? I tried $getname = mysql_query("SELECT Name FROM MyTable WHERE IP=$ip"); but this seems to return a Resource ID.
My apologizes if the question seems awfully elementary; I’m rather new to SQL (and PHP, for that matter). Also, I’m not in need for a secure way of authenticating for this one.
Use below code, after firing the query you have to iterate the result to get the output.