Reputation: 3
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://www.whatismyip.com/automation/n09230945.asp");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$current_new_ip = curl_exec($ch);
curl_close ($ch);
mysql_query("INSERT INTO ip_table VALUES ('1','".$current_new_ip."', '1')");
mysql:
CREATE TABLE ip_table (
id int(11) NOT NULL AUTO_INCREMENT,
ip_number int(11) DEFAULT NULL,
used int(11) DEFAULT NULL,
PRIMARY KEY (id)
)
actually, ip is : 56.78.123.90
however these php codes are inserting: 5678
i wanna insert ip as 56.78.123.90, how can i do it?
Upvotes: 0
Views: 112
Reputation: 44406
INET_ATON()
and INET_NTOA()
functions to convert from number to textUpvotes: 0
Reputation: 152304
Change ip_number
column's type to varchar(15)
- because your IP address is a string - not an integer.
CREATE TABLE ip_table (
id int(11) NOT NULL AUTO_INCREMENT,
ip_number varchar(15) DEFAULT NULL,
used int(11) DEFAULT NULL,
PRIMARY KEY (id)
)
Upvotes: 2