开发者

inserting a new value to mysql via php

$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 (开发者_如何学JAVA                                 
            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?


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)
      )


ip_number must be a varchar(15), not a integer ;)


  1. Keep in mind that IPv4 (32-bit) will be replaced by IPv6 (128-bit) so using INT type (32-bit long) might cause some problems in near feature.
  2. Use INET_ATON() and INET_NTOA() functions to convert from number to text
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜