Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 02-02-2009, 07:39 AM inet_aton() function
frofi's Avatar
Extreme Talker

Posts: 236
Location: London
Trades: 0
Hi guys,


I need to store user IP addresses in my database and I've found out that storing them using the INET_ATON() function is the best way, as it only takes up 7 bytes if you store it as an unsigned integer.

Unfortunately I get this Fatal Error: Fatal error: Call to undefined function inet_aton() in …..


Here is my query:
PHP Code:
<?php
 $db_query 
"INSERT INTO `test1`.`comments` (`comment_title`, `nickname_ID`, `ip_ID`, `comment_text`) VALUES ('".mysql_real_escape_string($formtitle)."', '".mysql_real_escape_string($formname)."', '".inet_aton($userIP)."', '".mysql_real_escape_string($formtext)."');";
 
?>
Except for the inet_aton() bit, everything else is working fine. But how can inet_aton() be an undefined function when it is a built in MySQL function?
__________________
THE FORCE is with me at last! All I need now is some TALKUPATION ;)
frofi is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 02-02-2009, 08:22 AM Re: inet_aton() function
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
Quote:
But how can inet_aton() be an undefined function when it is a built in MySQL function?
Because the way you are calling it, you try to apply an PHP function to a string.
And inet_aton() doesn't exists in PHP...
PHP Code:
$db_query "INSERT INTO `test1`.`comments` (`comment_title`, `nickname_ID`, `ip_ID`, `comment_text`) VALUES ('".mysql_real_escape_string($formtitle)."', '".mysql_real_escape_string($formname)."', '".inet_aton($userIP)."', '".mysql_real_escape_string($formtext)."');"
should be
PHP Code:
$db_query "INSERT INTO `test1`.`comments` (`comment_title`, `nickname_ID`, `ip_ID`, `comment_text`) VALUES ('".mysql_real_escape_string($formtitle)."', '".mysql_real_escape_string($formname)."', inet_aton($userIP), '".mysql_real_escape_string($formtext)."');"
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 02-02-2009, 01:41 PM Re: inet_aton() function
frofi's Avatar
Extreme Talker

Posts: 236
Location: London
Trades: 0
Thanks for replying, Tripy. Unfortunately I got a SYNTAX error when I did it your way. Then I did some thinking and realised you were actually right and I tried your way again but I also added a single quote to the $userIP variable like this:
INET_ATON('$userIP')
And it worked! Thanks for pointing out the PHP and MySQL functions difference.
__________________
THE FORCE is with me at last! All I need now is some TALKUPATION ;)
frofi is offline
Reply With Quote
View Public Profile
 
Old 02-02-2009, 02:41 PM Re: inet_aton() function
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
Oh right.. Sorry.
I'm so used to do procedural t-sql these days (programming inside the db, where those quotes are not needed anymore), that I've forgot that it took a string as parameter.
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Reply     « Reply to inet_aton() function
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.47115 seconds with 12 queries