Hi,
I have an array that has an IP address in index 2 and a port in index 3 which I'm trying to insert into a DB, I'm using the following code:
This will echo the first IP address and port and then returns an error with MySQL saying
The numbers being the second half of the IP and the port.. When I try entering the [3] data into the port column only it goes through OK, but when trying the IP it gives the same error so I'm assuming this has something to do with the periods. The datatype for the IP column is char(15) and the port is an integer.
Does anyone know where I'm going wrong?
I have an array that has an IP address in index 2 and a port in index 3 which I'm trying to insert into a DB, I'm using the following code:
PHP:
$sqlcon = mysql_connect("localhost", "root", "password");
mysql_select_db("mydb", $sqlcon);
foreach ($result as $val) {
echo "$val[2]:$val[3]<br />";
$sql = "INSERT INTO mytable (IP, PORT) VALUES($val[2], $val[3])";
mysql_query($sql, $sqlcon) or die(mysql_error());
}
mysql_close($sqlcon)
Code:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '.185.112, 8080)' at line 1
Does anyone know where I'm going wrong?