Skip to content

Instantly share code, notes, and snippets.

@griggsk
Created November 29, 2010 19:53
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save griggsk/720484 to your computer and use it in GitHub Desktop.
Save griggsk/720484 to your computer and use it in GitHub Desktop.
Computer Availability status change script
#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);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment