I'm trying to write code to get ip from a table and ping and insert ip and response time another table. What I wrote is given below. It echo ip and response time but only ips are inserted to the table. Response times are blank.
Schema
+-------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+----------------+
| id | int(6) | NO | PRI | NULL | auto_increment |
| ip | varchar(30) | NO | | NULL | |
+-----------+-------------+------+-----+-------------------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------+-------------+------+-----+-------------------+-------+
| Log_time | timestamp | NO | | CURRENT_TIMESTAMP | |
| ip | varchar(30) | NO | | NULL | |
| Ping_time | varchar(30) | YES | | NULL | |
Code
<?php
// Connects to your Database
mysql_connect("localhost","xxx","xxx");
//database connection
mysql_select_db("xxxxx") or die(mysql_error());
$sql="select * from iplist where id=(SELECT MAX(id) FROM iplist)";
$data = mysql_query($sql) or die(mysql_error());
//asing ip to variables
$row = mysql_fetch_assoc($data);
$id=$row["id"];
$id1=$id;
while($id1>0) {
$sql="select ip from iplist where id=($id1)";
$data = mysql_query($sql) or die(mysql_error());
$row = mysql_fetch_assoc($data);
$ip=$row["ip"];
//ping ips
$ip_ad=$ip;
$ping = system("ping -c 1 $ip_ad | head -n 2 | tail -n 1 | awk '{print $7}'", $ping_time);
print $ping_time[0]; // First item in array, since exec returns an array.
$responcetime = $ping_time[0];
$dilay=$responcetime;
echo $ip;
echo $dilay;
//send data to database
//inserting data order
$order = "INSERT INTO Ping_log (ip, Ping_time) VALUES ('$ip','$dilay')";
//declare in the order variable
$result = mysql_query($order); //order executes
$id1 --;
}
?>