public
Created

Computer Availability status change script

  • Download Gist
statuschange.php
PHP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
#add your database username and password
$user="username";
$password="password";
$database="computer_availability";
 
#unless the computers name was empty
if($_POST['workstation'] != ""){
$workstation = strtoupper($_POST['workstation']);
}
else{ #build the computer's name from the host
 
$host_domain = strstr($_POST['host'], '.');
$workstation = strtoupper(str_replace($host_domain, '', $_POST['host']));
}
 
#connect to the database
$DB = mysql_connect('mysqlcluster.adm.yourmysqlserver.edu', $user, $password);
@mysql_select_db($database) or die("Unable to select database");
 
#get the computer's row based on it's name
$checkQuery = "SELECT computer_name FROM compstatus WHERE computer_name = '".$workstation."'";
$result = mysql_query($checkQuery);
 
#if we find a computer update it's status
if(mysql_numrows($result)>0){
$query="UPDATE `compstatus` SET status = '".$_POST['status']."' WHERE computer_name = '".$workstation."'";
mysql_query($query) or die(mysql_error());
}
 
mysql_close($DB);

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.