phpBeginner06 Posted December 7, 2006 Share Posted December 7, 2006 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? Link to comment https://forums.phpfreaks.com/topic/29776-displaying-error-message-when-page-does-not-exist/ Share on other sites More sharing options...
The Little Guy Posted December 7, 2006 Share Posted December 7, 2006 [code]$sql = mysql_query("SQL STUFF");$row = mysql_fetch_array($sql);if(!$row){ echo 'Page No Longer Exists';}[/code] Link to comment https://forums.phpfreaks.com/topic/29776-displaying-error-message-when-page-does-not-exist/#findComment-136735 Share on other sites More sharing options...
phpBeginner06 Posted December 7, 2006 Author Share Posted December 7, 2006 Little Guy - Tried your example; but it echoed "Page No Longer Exists" on the web page when I did have the row and when I did not have the row (both ways - it still displays the same). What am I doing wrong? Link to comment https://forums.phpfreaks.com/topic/29776-displaying-error-message-when-page-does-not-exist/#findComment-136747 Share on other sites More sharing options...
trq Posted December 7, 2006 Share Posted December 7, 2006 [code]<?php if ($result = mysql_query($sql)) { if (mysql_num_rows($result) == 0) { echo "No record found"; } else { $row = mysql_fetch_array($result); } }?>[/code] Link to comment https://forums.phpfreaks.com/topic/29776-displaying-error-message-when-page-does-not-exist/#findComment-136758 Share on other sites More sharing options...
phpBeginner06 Posted December 7, 2006 Author Share Posted December 7, 2006 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 passwordmysql_connect("mysql","username","password"); //select which database you want to editmysql_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> ";echo $row["year"];echo "</div>";echo "<div style='text-align:left;padding-left:5px'><span style='font-weight:bold'>Make:</span> ";echo $row["make"];echo "</div>";echo "<div style='text-align:left;padding-left:5px'><span style='font-weight:bold'>Model:</span> ";echo $row["model"];echo "</div>";echo "<div style='text-align:left;padding-left:5px'><span style='font-weight:bold'>Series:</span> ";echo $row["series"];echo "</div>";echo "<div style='text-align:left;padding-left:5px'><span style='font-weight:bold'>Style:</span> ";echo $row["style"];echo "</div>";echo "<div style='text-align:left;padding-left:5px'><span style='font-weight:bold'>Special Edition:</span> ";echo $row["edition"];echo "</div>";echo "<div style='text-align:left;padding-left:5px'><span style='font-weight:bold'>Mileage:</span> ";echo $row["mileage"];echo "</div>";echo "<div style='text-align:left;padding-left:5px'><span style='font-weight:bold'>Exterior Color:</span> ";echo $row["extcolor"];echo "</div>";echo "<div style='text-align:left;padding-left:5px'><span style='font-weight:bold'>Interior Color:</span> ";echo $row["intcolor"];echo "</div>";echo "<div style='text-align:left;padding-left:5px'><span style='font-weight:bold'>Number of Doors:</span> ";echo $row["doors"];echo "</div>";echo "<div style='text-align:left;padding-left:5px'><span style='font-weight:bold'>Engine:</span> ";echo $row["engine"];echo "</div>";echo "<div style='text-align:left;padding-left:5px'><span style='font-weight:bold'>Tranmission:</span> ";echo $row["transmission"];echo "</div>";echo "<div style='text-align:left;padding-left:5px'><span style='font-weight:bold'>Fuel Used:</span> ";echo $row["fuel"];echo "</div>";echo "<div style='text-align:left;padding-left:5px'><span style='font-weight:bold'>Stereo:</span> ";echo $row["stereo"];echo "</div>";echo "<div style='text-align:left;padding-left:5px'><span style='font-weight:bold'>Drive Terrain:</span> ";echo $row["driveterrain"];echo "</div>";echo "<div style='text-align:left;padding-left:5px'><span style='font-weight:bold'>Vehicle's Condition:</span> ";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: ";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> ";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? Link to comment https://forums.phpfreaks.com/topic/29776-displaying-error-message-when-page-does-not-exist/#findComment-136906 Share on other sites More sharing options...
marcus Posted December 7, 2006 Share Posted December 7, 2006 basically put it before the while[code]<?phpif(mysql_num_rows($result) == 0){echo "error";}else {while....etc...?>[/code] Link to comment https://forums.phpfreaks.com/topic/29776-displaying-error-message-when-page-does-not-exist/#findComment-136908 Share on other sites More sharing options...
trq Posted December 7, 2006 Share Posted December 7, 2006 [code]<?php if ($result = mysql_query($sql)) { if (mysql_num_rows($result) == 0) { echo "No record found"; } else { // your while goes here. } }?>[/code] Link to comment https://forums.phpfreaks.com/topic/29776-displaying-error-message-when-page-does-not-exist/#findComment-136909 Share on other sites More sharing options...
phpBeginner06 Posted December 7, 2006 Author Share Posted December 7, 2006 Thanks Guys - Really Appericate Your Help - Got It To Implement Great !!! ;D Link to comment https://forums.phpfreaks.com/topic/29776-displaying-error-message-when-page-does-not-exist/#findComment-136985 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.