Jump to content

Displaying Error Message When Page Does Not Exist ???


phpBeginner06

Recommended Posts

How can I display a error message to end users; when the go to a page that it not longer exist? The reason it would not longer exist is because I would have deleted the row/record from my database.

[u]Example:[/u]

 Say I create a new row/record in my database and then create a link in a page to display a query in a PHP web page (ie. "http://www.domain.com/product.php?id=5").

Then later I sold that product; so I went into my database and deleted this row/record.

The problem is; what if someone has created a shortcut to the web page "http://www.domain.com/product.php?id=5"; when they come back to the page all the information is gone and/or the page is messed up.

I want to be able to tell them that "this products has been sold"; with a message within the page.

I tried to use die(); but either I cannot use it for this or I am using it wrong. I also have been reading about URL validation; is this what I need to do, too display a error message and if so, how do I go about validating my URLs?
Where would I put the above code at in the code I have below? I tried putting it right before "while statement"; but then I could not see the content that was previously there at all (not even error echo).
[code]<?

//connect to mysql
//change user and password to your mySQL name and password
mysql_connect("mysql","username","password");

//select which database you want to edit
mysql_select_db("vehicleList");

$id = $_GET['id'];
$search = "SELECT * FROM details WHERE id = '$id'";
$result = mysql_query($search);

while ($row = mysql_fetch_array($result)) {

echo "<table width=90% height=400px align=center valign=center style='border:solid 1px navy;margin-bottom:0px' cellpadding=0 cellspacing=0>";
echo "<td style='border-right:solid 1px navy' align=left valign=top width=50%>";
echo "<div style='text-align:left;padding-left:5px;padding-top:10px'><span style='font-weight:bold'>Year:</span>&nbsp;&nbsp;";
echo $row["year"];
echo "</div>";
echo "<div style='text-align:left;padding-left:5px'><span style='font-weight:bold'>Make:</span>&nbsp;&nbsp;";
echo $row["make"];
echo "</div>";
echo "<div style='text-align:left;padding-left:5px'><span style='font-weight:bold'>Model:</span>&nbsp;&nbsp;";
echo $row["model"];
echo "</div>";
echo "<div style='text-align:left;padding-left:5px'><span style='font-weight:bold'>Series:</span>&nbsp;&nbsp;";
echo $row["series"];
echo "</div>";
echo "<div style='text-align:left;padding-left:5px'><span style='font-weight:bold'>Style:</span>&nbsp;&nbsp;";
echo $row["style"];
echo "</div>";
echo "<div style='text-align:left;padding-left:5px'><span style='font-weight:bold'>Special Edition:</span>&nbsp;&nbsp;";
echo $row["edition"];
echo "</div>";
echo "<div style='text-align:left;padding-left:5px'><span style='font-weight:bold'>Mileage:</span>&nbsp;&nbsp;";
echo $row["mileage"];
echo "</div>";
echo "<div style='text-align:left;padding-left:5px'><span style='font-weight:bold'>Exterior Color:</span>&nbsp;&nbsp;";
echo $row["extcolor"];
echo "</div>";
echo "<div style='text-align:left;padding-left:5px'><span style='font-weight:bold'>Interior Color:</span>&nbsp;&nbsp;";
echo $row["intcolor"];
echo "</div>";
echo "<div style='text-align:left;padding-left:5px'><span style='font-weight:bold'>Number of Doors:</span>&nbsp;&nbsp;";
echo $row["doors"];
echo "</div>";
echo "<div style='text-align:left;padding-left:5px'><span style='font-weight:bold'>Engine:</span>&nbsp;&nbsp;";
echo $row["engine"];
echo "</div>";
echo "<div style='text-align:left;padding-left:5px'><span style='font-weight:bold'>Tranmission:</span>&nbsp;&nbsp;";
echo $row["transmission"];
echo "</div>";
echo "<div style='text-align:left;padding-left:5px'><span style='font-weight:bold'>Fuel Used:</span>&nbsp;&nbsp;";
echo $row["fuel"];
echo "</div>";
echo "<div style='text-align:left;padding-left:5px'><span style='font-weight:bold'>Stereo:</span>&nbsp;&nbsp;";
echo $row["stereo"];
echo "</div>";
echo "<div style='text-align:left;padding-left:5px'><span style='font-weight:bold'>Drive Terrain:</span>&nbsp;&nbsp;";
echo $row["driveterrain"];
echo "</div>";
echo "<div style='text-align:left;padding-left:5px'><span style='font-weight:bold'>Vehicle's Condition:</span>&nbsp;&nbsp;";
echo $row["condition"];
echo "</div>";
echo "<div style='text-align:left;padding-left:5px;color:darkred;font-weight:bold;margin-top:75px;font-size:20px'>Price:&nbsp;";
echo $row["price"];
echo ".00";
echo "</div>";
echo "</td>";
echo "<td valign=top width=50% style='border:solid 0px white;padding-left:5;padding-right:5px'>";
echo "<div id='info' style='font-size:17;padding-top:10px'><u style='font-weight:bold'>Also Includes:</u>&nbsp;&nbsp;";
echo $row["standardfeatures"];
echo "</div>";
echo "</td>";
echo "</table>";

}

?>
[/code]

I have three sections of code like this; will I have to use the code for an error message in each of the three or only one?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.