When I write
if ($_GET["id"]) {
echo "Valor de id es " . $_GET["id"];
}
else
echo "no está definido id"
}
If "id" is defined all OK.
But if is not defined:
Undefined index: submit in c:\inetpub\wwwroot\php\ej07.php on line 6
How can I do?
Array Error
Moderator: General Moderators
If there are no parameters passed in the address line, then the $_GET array will not contain an index called id or anything else. So the index is undefined.
Try this instead:
Also check you brackets
Try this instead:
Code: Select all
<?php
$id = $_GETї"id"];
if ($id != "")
{
echo "Valor de id es " . $id;
}
else
{
echo "no está definido id"
}
?>- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
If you use empty() instead of isset() then you'll also be able to catch the situation where a user has modified the URL so that id is an empty string or 0:
Never trust your users
... (using trim() on all user input's a good idea too...)
Mac
Code: Select all
if (!empty($_GETї'id'])) {
echo 'Valor de id es '. $_GETї'id'];
} else {
echo 'no está definido id';
}Mac