I am passing a value in the querystring of a hyperlink and using the following code to trap the value:
$ItemID = $_GET["ID"];
if ($ItemID == "");
{
$ItemID = 1;
}
If no value is passed, $ItemID is set to 1, this works, however I get the notice:
Undefined index: ID
How do I prevent this?
Thanks in Adv.
$_GET and Querystring
Moderator: General Moderators
if no parameter ID is passed via GET that array $_GET does not have an element ID. That's what php is complaining about (not an error, only a warning)
Code: Select all
if(isset($_GET['ID']) && $_GET['ID'] !== '')
$ItemID = (int)$_GET['ID'];
else
$ItemID = 1;http://www.php.net/manual/en/function.e ... orting.php but I strongly advise against decreasing the reporting-level while developing.
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
I firmly agree with volka - lowering the error reporting doesn't fix the problem, it only hides it. Much better to learn how to prevent it in the first place:
http://www.php.net/manual/en/function.empty.php
http://www.php.net/manual/en/function.isset.php
Mac
http://www.php.net/manual/en/function.empty.php
http://www.php.net/manual/en/function.isset.php
Mac