Created
November 29, 2010 19:53
-
-
Save griggsk/720484 to your computer and use it in GitHub Desktop.
Computer Availability status change script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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