Hello guys, i have been away in the last few days, because of work, so i am on again.
I am trying to ping a series of hosts and then add info about the ping in a row.
I have a DB called ad, with a table called ping with row comp and row ping.
In row comp i have 400+ hostnames, and in row ping i need to insert the stat of that host. (if it is online or not)
I have the following code but if is not updating the row ping.
The simple PHP ping code is:
<?php
$comp = "127.0.0.1";
$str = exec("ping -n 1 -w 1 $comp", $input, $result);
if ($result == 0){
echo "Connected";
}else{
echo "Disconnected";
}
?>
This is a relatively simple code.
Now my modified code (that is not working):
<?php
include 'config_all.php';
$con = mysql_connect("$sqlhost","$sqluser","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
$sel = mysql_select_db("ad", $con);
if (!$sel)
{
die('Could not select DB: ' . mysql_error());
}
$on = "On";
$off = "Off";
$comp = mysql_query("SELECT * FROM comp");
//$comp ="PT1n1894";
$str = exec("ping -n 1 -w 1 $comp", $input, $result);
if ($result == 0){
mysql_query("
INSERT INTO
$table_ping (ping)
VALUES
('$on')
");
}else{
mysql_query("
INSERT INTO
$table_ping (ping)
VALUES
('$off')
");
}
?>
I now that there is something wrong, but i cannot see... diafol can you help please?