My code problem isn't solved yet but I am really thankful to see a lot of people trying to help me out... Thank you, guys... I really appreciate it!
Now, back to the code... The ID that is existing in TrackBox table is "000001" and I wanted to see the result showing the DATE and the LOCATION.
if (mysql_num_rows($result)> 1)
{
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>";
}
Originally, the code I was using gave me results... If I queried the ID "000001", it shows:
<font face='verdana' size='-1'><table border='1' width='40%'>
<tr>
<th
<b>Date</b></th>
<th
<b>Location</b></th>
</tr><h5>This is your current status...</h5><tr><td align=center>2007-01-30</td><td align=center>Boston</td></tr></table></font>
The original code looked like this...
<?php
// Database connection details.
$username = "username";
$password = "password";
$database = "database";
$id = $_REQUEST['invNum'];
#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 `DATE`, `LOCATION` FROM TrackBox WHERE ID = '$id'");
#EXECUTE QUERY
$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>";
}
?>
But I wanted the data to undergo validation, so I tried to ask help here and thankfully, Laserlight came to the rescue. The validation worked, but the results were not showing...
This is how my code looks like now:
<?php
// Database connection details.
$username = "username";
$password = "password";
$database = "database";
// Connect to the database.
$conn = @mysql_connect('localhost', $username, $password) or die("Unable to connect to MySQL");
@mysql_select_db($database, $conn) or die( "Unable to select database");
// Validate invNum.
if (isset($_REQUEST['invNum']) && strlen($_REQUEST['invNum']) == 6)
{
// Cast invNum to int to prevent SQL injection.
$id = (int)$_REQUEST['invNum'];
// Select the status.
$query = "SELECT `DATE`, `LOCATION` FROM TrackBox WHERE ID = '$id'";
$result = mysql_query($query, $conn) or die("Query failed: ($query): " . mysql_error());
// Display status if there is at least one row.
if (mysql_num_rows($result) > 0)
{
// print table header
while ($row = mysql_fetch_assoc($result))
{
// print current status
if (mysql_num_rows($result)> 1)
{
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>";
}
// print table footer
}
else
{
echo 'This number cannot be found in our records. Please contact us.';
// DEBUG
echo "<pre>The query was:\n$query</pre>";
// END DEBUG
}
mysql_close($conn);
}
else
{
echo 'You did not enter 6 characters. Please go <a href="javascript:history.back(-1);">back</a>.';
}
?>
Any changes I should do?