inserting a new value to mysql via php

514
$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?

173

Answer

Solution:

Changeip_number column's type tovarchar(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)
      )
94

Answer

Solution:

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

408

Answer

Solution:

  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 and functions to convert from number to text

People are also looking for solutions to the problem: PHP: passing php variables as arguments?

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.