search function error
3 posts by 2 authors in: Forums > CMS Builder
Last Post: March 19, 2010 (RSS)
We are using a search function that uses:
$search_type = $_GET['search_type'];
However, the page throws the error: Undefined index if no "search_type" is passed.
What would be the proper syntax to check if a variable is passed and if none is passed assign it one or suppress the error.
Thank you,
Chris
$search_type = $_GET['search_type'];
However, the page throws the error: Undefined index if no "search_type" is passed.
What would be the proper syntax to check if a variable is passed and if none is passed assign it one or suppress the error.
Thank you,
Chris
Re: [Christopherb] search function error
By Chris - March 18, 2010 - edited: March 18, 2010
Hi Christopherb,
Without seeing the full PHP source code, I can't say for sure whether this will be a good fix, but here's how to supress that error message:
Adding an @ like this is common practice when dealing with keys that might not be set (such as form data.) The result will be that $search_type will be == "".
I hope this helps. Please let me know if you have any questions.
Without seeing the full PHP source code, I can't say for sure whether this will be a good fix, but here's how to supress that error message:
$search_type = @$_GET['search_type'];
Adding an @ like this is common practice when dealing with keys that might not be set (such as form data.) The result will be that $search_type will be == "".
I hope this helps. Please let me know if you have any questions.
All the best,
Chris
Chris