Jump to content

Archived

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

markspec87

Get ID error catching

Recommended Posts

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

Share this post


Link to post
Share on other sites
[code]
<?
$id = $_GET[id];
if ($id == "") {
echo "No data specified";
}
?>
[/code]
same thing as above but the person forgot to set the $id variable

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites

×

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.