Jump to content


Photo

Get ID error catching


  • Please log in to reply
4 replies to this topic

#1 markspec87

markspec87
  • Members
  • PipPipPip
  • Advanced Member
  • 63 posts

Posted 01 August 2006 - 03:30 PM

ive got a page where i use this code to display data from my database.

$query="SELECT * FROM results WHERE autonumber = $_GET[id]";

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 :)

#2 hostfreak

hostfreak
  • Members
  • PipPipPip
  • Advanced Member
  • 581 posts

Posted 01 August 2006 - 03:32 PM

Try:

if ($id == "") {
echo "No data specified<br>";
}
else {
//other code
}


#3 desithugg

desithugg
  • Members
  • PipPipPip
  • Advanced Member
  • 281 posts
  • LocationScarborough

Posted 01 August 2006 - 03:35 PM

<?
$id = $_GET[id];
if ($id == "") {
echo "No data specified";
}
?>
same thing as above but the person forgot to set the $id variable

#4 hostfreak

hostfreak
  • Members
  • PipPipPip
  • Advanced Member
  • 581 posts

Posted 01 August 2006 - 03:39 PM

Oops, good catch.

#5 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 01 August 2006 - 03:49 PM

This is better, added a bit of data validation.
if(empty($_GET['id']) || !is_numeric($_GET['id']))
{
  echo "The data provide is either invalid or was not specified.";
}





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users