Hi, I have a mysql table named resourcescheduling with the following fields:
Computer_ID, Lab_ID, Schedule_Start_Date, Schedule_End_Date.
I want to do a search where a user inputs a computer no. and a lab no into two seperate input boxes to see if the computer is taken within certain dates. I am new to php so I am not too confident with it. The code below is the code I have used but I keep getting these erroe messages:
Notice: Undefined variable: ComputerName in C:\Inetpub\wwwroot\itlab\html\ComputerSearchResults.php on line 13
Notice: Undefined variable: LabName in C:\Inetpub\wwwroot\itlab\html\ComputerSearchResults.php on line 16
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\Inetpub\wwwroot\itlab\html\ComputerSearchResults.php on line 25
Does anyone know what these errors mean. Thank You in advance.
<form method=post action="CRSearch.php">
<div align="center"></div>
<table width="83%" border="1">
<tr>
<td width="28%"><div align="right">Search For: </div></td>
<td width="52%"> </td>
<td width="17%"> </td>
<td width="3%"> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td><div align="right">Computer Name: </div></td>
<td><div align="center">
<input type=text name=user size=25 maxlength=25>
</div></td>
<td><input name="submit" type=submit></td>
<td> </td>
</tr>
<tr>
<td><div align="right">Lab Name </div></td>
<td><div align="center">
<input type=text name=passwd size=25 maxlength=25>
</div></td>
<td> </td>
<td> </td>
</tr>
</table>
<p align="center">
<p align="center">
</form>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<?
//You should now this but be sure to connect to your database or this is useless. :/
$db = mysql_connect("localhost", "admin", "");
mysql_select_db("itlab", $db);
if ($ComputerName == "")
{$ComputerName = '%';}
if ($LabName == "")
{$LabName = '%';}
// $user and $passwd are the two column names I used. Change this to fit your database
$result = mysql_query ("SELECT * FROM resourcescheduling
WHERE Computer_ID LIKE '%$ComputerName%'
AND Lab_ID LIKE '%$LabName%
AND Schedule_Start_Date >='08/25/2003' and Schedule_End_Date <='08/31/2003' AND Confirmed = 'Reserved' ORDER BY Schedule_Start_Date");
if ($row = mysql_fetch_array($result)) {
do {
PRINT "<b>Computer Name: </b> ";
print $row["Computer_ID"];
print (" ");
print ("<br>");
PRINT "<b>Lab Name: </b> ";
print $row["Lab_ID"];
print ("<p>");
PRINT "<b>Start Date: </b> ";
print $row["Schedule_Start_Date"];
print ("<p>");
PRINT "<b>End Date: </b> ";
print $row["Schedule_End_Date"];
print ("<p>");
} while($row = mysql_fetch_array($result));
} else {print "Sorry, no records were found!";}
//The end result prints the username / passwd / firstname / lastname / ID / email
//you will have to change these fields also to fit your needs
?>
</body>
</html>