desjardins2010 Posted December 14, 2010 Share Posted December 14, 2010 I'm trying to get a field in the data base to accept the value 192.168.1.1 or an IP address for that matter I have tried decimal and bigint all come back cutting it and only showing 192 Quote Link to comment https://forums.phpfreaks.com/topic/221631-how-to-get-database-to-accept/ Share on other sites More sharing options...
PFMaBiSmAd Posted December 14, 2010 Share Posted December 14, 2010 Ip addresses are not numbers. They are made up of numeric digits and periods to separate the different parts. You either need to store them using a character/text type or convert them to a number (see the mysql INET_ATON() and INET_NTOA() functions.) Quote Link to comment https://forums.phpfreaks.com/topic/221631-how-to-get-database-to-accept/#findComment-1147197 Share on other sites More sharing options...
desjardins2010 Posted December 14, 2010 Author Share Posted December 14, 2010 I'm reading the inet_aton functions now... so setting up the database though I have a field called IPadress so I enter anything in there? to compare too? not sure how to accomplish this I see the fucntion calls for a mathamatical equation that will convert the IP to a numaric number but how do I get the inital entry? Quote Link to comment https://forums.phpfreaks.com/topic/221631-how-to-get-database-to-accept/#findComment-1147201 Share on other sites More sharing options...
Adam Posted December 14, 2010 Share Posted December 14, 2010 Assume you have the following table: create table ip_table ( ip_col int unsigned ); When you're inserting the IP originally you'd have a query like: insert into ip_table (ip_col) values ( inet_aton('127.0.0.1') ); Then to retrieve a specific IP, in it's normal format: select inet_ntoa(ip_col) from ip_table where inet_ntoa(ip_col) = '127.0.0.1'; Obviously '127.0.0.1' would be replaced by a PHP variable. Quote Link to comment https://forums.phpfreaks.com/topic/221631-how-to-get-database-to-accept/#findComment-1147245 Share on other sites More sharing options...
desjardins2010 Posted December 14, 2010 Author Share Posted December 14, 2010 hmmm that makes sence... but to add the IP to database when they register lets say they are going to be given a few initial values level, ip, cash extt i can't just say insert into blah blah blah 192.169.1.1 I have to enter it as an inet_iton??? Quote Link to comment https://forums.phpfreaks.com/topic/221631-how-to-get-database-to-accept/#findComment-1147251 Share on other sites More sharing options...
Adam Posted December 14, 2010 Share Posted December 14, 2010 Do it like in the example insert statement, pass the IP into inet_aton(). Quote Link to comment https://forums.phpfreaks.com/topic/221631-how-to-get-database-to-accept/#findComment-1147293 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.