webmaster1 Posted November 15, 2008 Share Posted November 15, 2008 Hi Freaks! I'm trying to insert an ip address into a mySQL table: $ipaddress = getenv('REMOTE_ADDR'); My ip address field is set as mediumint(9) but I only end up with four digits in my database. Is my field set incorrectly or do I need to adjust my php code? Link to comment https://forums.phpfreaks.com/topic/132827-solved-inserting-ip-address-into-mysql-using-a-php-form/ Share on other sites More sharing options...
.josh Posted November 15, 2008 Share Posted November 15, 2008 ip address is a string type. use varchar Link to comment https://forums.phpfreaks.com/topic/132827-solved-inserting-ip-address-into-mysql-using-a-php-form/#findComment-690793 Share on other sites More sharing options...
webmaster1 Posted November 15, 2008 Author Share Posted November 15, 2008 ip address is a string type. use varchar Wow, that was simple. Works fine now, thanks! Link to comment https://forums.phpfreaks.com/topic/132827-solved-inserting-ip-address-into-mysql-using-a-php-form/#findComment-690796 Share on other sites More sharing options...
Mchl Posted November 15, 2008 Share Posted November 15, 2008 Actually recommended way to do this, is with numeric field type and INET_ATON() and INET_NTOA() functions. This way IP will be stored in 4 or 8 bytes, while for string you need as much as 15. Link to comment https://forums.phpfreaks.com/topic/132827-solved-inserting-ip-address-into-mysql-using-a-php-form/#findComment-690799 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.