I am creating small search engine for job portal. I used following code for searching.
<form method="get" action="search.php">
<input type="text" name="keyword">
<input type="text" name="location">
</form>
when I search it sends input by url and displays the results.
e.g : url: localhost/jobportal/search.php?keyword=php&location=India
But if I directly open the page by entering url : "localhost/jobportal/search.php" in browser, it shows following error.
Notice: Undefined index: keyword in C:\xampp\htdocs\jobportal\search\index.php on line 384
Notice: Undefined index: location in C:\xampp\htdocs\jobportal\search\index.php on line 385
I know why this error is occurring I only need to know how to avoid this error.
Just add a check if they exists. Use
empty
. -empty()
will check if it isset
and thevalue
is notnull
orfalse
.