As you can see from my code, I am obviously a PHP beginner. Can anyone offer any suggestions as to why the code will work at some times, and not at others. For example, I can enter all my information on the form, click the submit button, and see the confirmation page with the information that was entered on the previous form. However, there are times when I do the exact same thing, and DO NOT see the information that I entered on the form, instead, I see the information of the last successfully entered work order. Any suggestions?
<?php
global $conn;
$conn = mysql_connect("******", "*", "******") or die(mysql_error());
mysql_select_db("workorder", $conn) or die(mysql_error());
$display1="
<form method=\"POST\" action=\"$_SERVER[PHP_SELF]\">
Please provide the following user information: <p></p>
<table width=\"500\" border=\"0\">
<tr>
<td ALIGN=\"right\" width=45%>Enter User Name:</td>
<td><input type =\"text\" name=\"User\" size = 30 ></td>
</tr>
</table>
";
$display2="
<table width=\"500\" border=\"0\">
<tr>
<td ALIGN=\"right\" width=45%>Enter Room # / Department: </td>
<td><input type =\"text\" name=\"Room\" size = 30></TD>
</TR>
<tr>
<td ALIGN=\"right\" width=45%>Enter Phone Number:</td>
<td><input type =\"text\" name=\"Phone\" size = 30></td>
</tr>
<tr>
<td ALIGN=\"right\" width=45%>Enter user's E-Mail address: </td>
<td><input type=\"text\" name=\"EMail\" size = 30 value = \"@lcps.k12.nm.us\"></td>
</tr>
</table>
<br>";
$display3="
<table width=\"500\" border=\"0\">
<tr>
<td ALIGN=\"right\" width=45%>Enter Model Number: </td>
<td><input type=\"text\" name=\"Model\" size = 30> </td>
</tr>
</table>";
$display4="
<table width=\"500\" border=\"0\">
<tr>
Describe the problem that you encountered:
<textarea wrap =\"virtual\" name = \"Problem\" row=15 cols=45> </textarea>
</tr>
<tr>
Describe your attempt to fix the problem:
<textarea wrap =\"virtual\" name = \"Attempt\" row=15 cols=45> </textarea>
</tr>
<tr>
<td ALIGN=\"right\" width=45%>Requested by: </td>
<td> <input type = \"Text\" name = \"Requestor\" size = 30> </td>
</tr>
<tr>
<td ALIGN=\"right\" width=45%> Requestor's E-Mail:</td>
<td> <input type = \"text\" name = \"ReqMail\" size = 30 value = \"@lcps.k12.nm.us\"> </td>
</tr>
</table>
<input type=\"submit\" name=\"submit\" value=\"Enter Work Order\">
</form>";
$display5 = "
<table width=\"500\" border=\"0\">
<tr>
<td ALIGN=\"right\" width=45%>Enter Bar Code #: </td>
<td><input type=\"text\" name=\"Barcode\" size = 30> </td>
</tr>
</table>";
function enhanced_list_box($options){
$sql = "select " . $options['id_field'];
$sql .= ", " . $options['value_field'];
$sql .= " from " . $options['table'];
/ append any where criteria to the sql /
if(isset($options['where_statement'])) {
$sql .= " where " . $options['where_statement'] ;
}
/ set the sort order of the list /
$sql .= " order by " . $options['value_field'];
$result = mysql_query($sql)
or die("error in SQL");
echo '<select name="', $options['id_field'], '" size="1">';
//$display6 = "<select name=\", $options[id_field], \" size=\"1\">";
while ($row = mysql_fetch_array($result, MYSQL_NUM))
{
if($row[0] == $options['highlight_id']) {
echo '<option value="', $row[0], '" SELECTED>',
$row[1], '</option>';
} else {
echo '<option value="', $row[0], '">',
$row[1], '</option>';
}
}
echo '</select>';
}
$reqmail = $POST["ReqMail"];
$UserMail = $POST["EMail"];
$room = $POST["Room"];
$username = $POST["User"];
$Requestor = $POST["Requestor"];
$Phone = $POST["Phone"];
$computermake = $POST["computermake"];
$Model = $POST["Model"];
$Barcode = $POST["Barcode"];
$operatingsystem = $POST["operatingsystem"];
$Problem = $POST["Problem"];
$Attempt = $POST["Attempt"];
//$Tech = $POST["Technician"];
$Location = $POST["name"];
$today=time();
$mySQLDate = date("m-d-Y", $today);
$_SESSION[today] = $mySQLDate;
$LocationName= "select name from listing where locationcode = '$Location'";
$LocationResult = mysql_query ($LocationName);
$_SESSION[res] = mysql_fetch_row ($LocationResult);
if ($_POST["submit"] == "Enter Work Order" and (empty($reqmail) or empty($UserMail) or empty($room) or empty($username) or empty ($Requestor) or empty($Phone) or empty($computermake) or empty($Model) or empty($Barcode) or empty($operatingsystem) or empty($Problem) or empty($Attempt) or empty($Location))) {
echo "Please enter a value in ALL fields.";
}
else if ($POST["submit"] == "Enter Work Order" and (!empty($reqmail) and !empty($UserMail) and !empty($room) and !empty($username) and !empty ($Requestor) and !empty($Phone) and !empty($computermake) and !empty($Model) and !empty($Barcode) and !empty($operatingsystem) and !empty($Problem) and !empty($Attempt) and !empty($Location)))
{
$techID = "select TechnicianID from listing where name = '$POST[name]'";
$TechIDRes = mysql_query ($techID, $conn);
$array = mysql_fetch_array ($TechIDRes);
$teckID = $array[0];
$technicianName = "select Technician from technicians where TechnicianID = '$teckID'";
$technicianNameRes = mysql_query ($technicianName);
$array2 = mysql_fetch_row($technicianNameRes);
$teckName = $array2[0];
$result = "insert into workorder (Open, ReqEmail, EMail, Room, WorkOrderNumber, UserName, RequestedBy, Phone, ComputerMake, ComputerModel, InventoryNumber, OperatingSystem, Problem, Attempted, TechnicianID, LocationCode, DateCompleted, Solution, completedby, dateentered) VALUES ('O', '$reqmail', '$UserMail', '$room', '', '$username', '$Requestor', '$Phone', '$computermake', '$Model', '$Barcode', '$operatingsystem', '$Problem', '$Attempt', '$teckName', '$Location', NULL, NULL, NULL, now())";
$sql = mysql_query ($result);
header("Location: http://lcps_web/wool/conftest.php");
}
?>
<?
echo $display1;
echo "<table width=\"500\" border=\"0\">
<tr> <td ALIGN=\"right\" width=45%>Select Location:</td> ";
echo "<td>";
enhanced_list_box(array(
'table' => 'listing',
'id_field' => 'name',
'value_field' => 'name',
'highlight_id' => 4
));
echo "</td> </tr> </table>";
echo $display2;
echo "Please provide the following product information:<P>";
echo "<table width=\"500\" border=\"0\">
<tr> <td ALIGN=\"right\" width=45%> Select Computer Make:</td> ";
echo "<td>";
enhanced_list_box(array(
'table' => 'computermake',
'id_field' => 'computermake',
'value_field' => 'computermake',
'highlight_id' => 4));
echo "</td> </tr> </table>";
echo $display3;
echo "<table width=\"500\" border=\"0\">
<tr> <td ALIGN=\"right\" width=45%> Select Operating System:</td>";
echo "<td>";
enhanced_list_box(array(
'table' => 'operatingsystem',
'id_field' => 'operatingsystem',
'value_field' => 'operatingsystem',
'highlight_id' => 4));
echo "</td> </tr> </table>";
echo $display5;
echo $display4;
?>