markspec87 Posted August 1, 2006 Share Posted August 1, 2006 ive got a page where i use this code to display data from my database.[code]$query="SELECT * FROM results WHERE autonumber = $_GET[id]";[/code]When they goto the index page and click a result it would goto "results.php?id=1/2/3/"And display the appropiate data.My question is, how can i get the page to display "No data specified" or something similar when someone just types results.php with no ID. At the moment it will just show the page with the database driven areas blank.thanks :) Quote Link to comment https://forums.phpfreaks.com/topic/16218-get-id-error-catching/ Share on other sites More sharing options...
hostfreak Posted August 1, 2006 Share Posted August 1, 2006 Try:[code]if ($id == "") {echo "No data specified<br>";}else {//other code}[/code] Quote Link to comment https://forums.phpfreaks.com/topic/16218-get-id-error-catching/#findComment-67093 Share on other sites More sharing options...
desithugg Posted August 1, 2006 Share Posted August 1, 2006 [code]<?$id = $_GET[id];if ($id == "") {echo "No data specified";}?>[/code]same thing as above but the person forgot to set the $id variable Quote Link to comment https://forums.phpfreaks.com/topic/16218-get-id-error-catching/#findComment-67094 Share on other sites More sharing options...
hostfreak Posted August 1, 2006 Share Posted August 1, 2006 Oops, good catch. Quote Link to comment https://forums.phpfreaks.com/topic/16218-get-id-error-catching/#findComment-67095 Share on other sites More sharing options...
wildteen88 Posted August 1, 2006 Share Posted August 1, 2006 This is better, added a bit of data validation.[code=php:0]if(empty($_GET['id']) || !is_numeric($_GET['id'])){ echo "The data provide is either invalid or was not specified.";}[/code] Quote Link to comment https://forums.phpfreaks.com/topic/16218-get-id-error-catching/#findComment-67099 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.