I know this piece of script is not the best way to write this but it actually worked when I started this project, but for some reason it no longer works. I was wondering if someone could take a look at it and give me some improvements or recommendations for it to work better.
I just added a way for the db to send an email when a workorder is updated. It checks to see if the tech has changed, if so, send him an email letting him know the workorder is now his. Should be simple. This script results in a blank page, no error messages.
<?php $woid = $_POST['woid']; $date = $_POST['date']; $rcvdby = $_POST['rcvdby']; $userid = $_POST['userid']; $problem = $_POST['problem']; $solution = $_POST['solution']; $status = $_POST['status']; $closeddt = $_POST['closeddt']; $partsused = $_POST['partsused']; $techid = $_POST['techid']; $catid = $_POST['catid']; $priority = $_POST['priority']; $poster = $_POST['poster']; $deptcode = $_POST['deptcode']; include("config.php"); dbConnect(); //Check to see what tech is assigned now $query1="SELECT techid FROM workorder WHERE woid = $woid"; $result1=mysql_query($query1); while($row1=mysql_fetch_array($result1,MYSQL_ASSOC)) $oldtechid = $row1['techid']; //Get the tech's email address $query2="SELECT techid, email FROM tech WHERE techid = $techid"; $result2=mysql_query($query2); while($row2=mysql_fetch_array($result2,MYSQL_ASSOC)) $email = $row2['email']; //Check to see if the old tech and new tech are different, if so send email to new tech if ($oldtechid <> $techid) $text="Workorder #: $woid has been assigned to you by $poster"; $headers = "From: Workorder Tracking\r\n"; mail($email, 'Workorder Update', $text, $headers); else //continue with updating the database with new changes. $query = "UPDATE workorder SET userid='$userid', problem='$problem', solution='$solution', status='$status', techid='$techid', catid='$catid', priority='$priority', poster='$poster', deptcode='$deptcode' WHERE woid=$woid"; $result = mysql_query($query) or die('Sorry, we could not edit this WO to the database at this time'); if ($result) echo "<h2><a href=\"index.php\">Workorder $woid Updated - Click Here Return to workorder</a></h2>\n"; else echo "<h2>Sorry, there was a problem editing your workorder</h2>\n"; ?>
Any help or pointers are greatly appreciated.