Running this in a batch file on windows to send a update to my server with the new ip info from the vpn.
It's putting in the right info but it keeps making new rows all the time when the IP address is the same. If I change the IP address in the csv file it won't make a new row
Thoughts?
<?php
$hostname = file_get_contents("hostname.csv");
$vpn_ip = file_get_contents("hostip.csv");
$dbhost = "####";
$dbuser = "####";
$dbpass = "####";
$dbname = "####";
$table = "computers";
mysql_connect($dbhost,$dbuser,$dbpass) or die("Unable to connect to database");
@mysql_select_db("$dbname") or die("Unable to select database $dbname");
$query = mysql_query("UPDATE $table SET vpn_ip = '$vpn_ip' WHERE hostname = '$hostname';");
if (mysql_affected_rows()== 0) {
$query = mysql_query("INSERT INTO $table VALUES ('', '$hostname', '$vpn_ip');");
}
mysql_close();
?>
Just to go over. Some computer names will be the same. So I just want their IP address to update only. If that computer name doesn't exist. Make a new row with the computer name and the current IP
But if their computer name hasn't changed I just want it to update the IP address.
TIA