[FONT="Arial"]Can anybody help me out with this?
I want to validate if the data really exists in the database.
The form requires the user to simply input a 6-character length number (name in form field is invNum) and I'd like to validate if the number (invNum=ID) exists in the database. If the number doesn't exist, I'd like to echo a message and not just give the user a blank form.
Here's my form:
[FONT="Verdana"]<form method="post" action="query.php" name="frmBox">
<table width="5%" border="0" cellspacing="1" cellpadding="1">
<tr>
<td>
<input name="invNum" maxlength="6" tabindex="6"/>
</td>
</tr>
<tr>
<td>
<input type="submit" name="submit" value="Track it!" class="button" tabindex="6"/>
</td>
</tr>
</table>
</form>[/FONT]
Here's my query.php file code:[/FONT]
[FONT="Verdana"]<?php
// get values from input form
$id = $_REQUEST['invNum'];
$username = "username";
$password = "password";
$database = "database";
#CONNECT TO MYSQL
$dbcnx = @mysql_connect('localhost',$username,$password) or die("Unable to connect to MySQL");
#CONNECT TO DATABASE
@mysql_select_db($database) or die( "Unable to select database");
#CREATE THE QUERY
$sql = ("SELECT * FROM TrackBox WHERE ID = '$id' ORDER BY date Limit 0, 30");
#EXECUTE QUERY
if($id == "")
{
// no number entered
{
die('You did not enter anything. Please go
<a href="javascript:history.back(-1);">back</a>.');
}
if (isset($id['ID']) AND
(strlen($id['ID']) >= 6) AND
(strlen($id['ID']) <= 5) )
// checking the length
{
die('Please enter 6 characters.');
}
if(!filter_var($id=='ID'))
echo "This number cannot be found in our records. Please contact us.";
}
else
{
$rs = mysql_query($sql,$dbcnx) or die(mysql_error());
echo "<font face='verdana' size='-1'><table border='1' width='40%'>
<tr>
<th\n><b>Date</b></th>
<th\n><b>Location</b></th>
</tr>";while($row = mysql_fetch_array($rs))
{
echo "<h5>" . "This is your current status..." . "</h5>";
echo "<tr>";
echo "<td align=center>" . $row['DATE'] . "</td>";
echo "<td align=center>" . $row['LOCATION'] . "</td>";
echo "</tr>";
}
echo "</table></font>";
mysql_close($dbcnx);
}
?> [/FONT]