koolgirl Posted June 5, 2006 Share Posted June 5, 2006 Higot tired trying to solve this problem. I have been using the following script to store visitor's data. It is working fine: <?php$dbcnx = @mysql_connect('mysql','username','mypass');mysql_select_db("Main");$sql = "INSERT INTO Records SET " ."IP='$REMOTE_ADDR', " . "BrowserName='$HTTP_USER_AGENT', " ."Language='$HTTP_ACCEPT_LANGUAGE', " . "Referer='$HTTP_REFERER', " . "Date=NOW()";***********************************************I want to store the user's host name also. I know this will display the host name on screen: <?echo "Your Host Name: " . gethostbyaddr($_SERVER['REMOTE_ADDR'])";?>************************************************but the problem is how to store it in database? it returns error if I write it this way: <?php$dbcnx = @mysql_connect('mysql','username','mypass');mysql_select_db("Main");$sql = "INSERT INTO Records SET " ."IP=gethostbyaddr($_SERVER['REMOTE_ADDR'])";******************************************All help would be very much appriciated. Many Thanks Quote Link to comment https://forums.phpfreaks.com/topic/11276-help-gethostbyaddr_serverremote_addr/ Share on other sites More sharing options...
kenrbnsn Posted June 5, 2006 Share Posted June 5, 2006 Try this:[code]<?php$sql = "INSERT INTO Records SET IP='" . gethostbyaddr($_SERVER['REMOTE_ADDR']) . "'";?>[/code]Ken Quote Link to comment https://forums.phpfreaks.com/topic/11276-help-gethostbyaddr_serverremote_addr/#findComment-42222 Share on other sites More sharing options...
poirot Posted June 6, 2006 Share Posted June 6, 2006 -Alternative Syntax-[code]<?php$sql = "INSERT INTO `records` (IP) VALUES ('" . gethostbyaddr($_SERVER['REMOTE_ADDR']) . "')";?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/11276-help-gethostbyaddr_serverremote_addr/#findComment-42277 Share on other sites More sharing options...
kenrbnsn Posted June 6, 2006 Share Posted June 6, 2006 No, using the "Set" is an alternative syntax for INSERT. It works fine. I use it all the time. Ken Quote Link to comment https://forums.phpfreaks.com/topic/11276-help-gethostbyaddr_serverremote_addr/#findComment-42280 Share on other sites More sharing options...
poirot Posted June 6, 2006 Share Posted June 6, 2006 Heh, my bad. I like this forum because you always learn something :) Quote Link to comment https://forums.phpfreaks.com/topic/11276-help-gethostbyaddr_serverremote_addr/#findComment-42281 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.