Reputation: 17185
I have a basic PHP script.
$hike_id = $_REQUEST['hike_id'];
$height = $_REQUEST['height'];
$width = $_REQUEST['width'];
Sometimes these are no such parameters passed into the request and I am guessing that is why the 500 error is being returned.
Is there a way to stop that page from returning the 500 error somehow? Here is an example of it: http://comehike.com/outdoors/hike_widget.php?hike_id=164&height=700&width=500
Upvotes: 0
Views: 264
Reputation: 1294
You could just conditionally assign the variables using ternary expressions and isset()
:
$hike_id = isset($_REQUEST['hike_id']) ? $_REQUEST['hike_id'] : 0;
$height = isset($_REQUEST['height']) ? $_REQUEST['height'] : 0;
$width = isset($_REQUEST['width']) ? $_REQUEST['width'] : 0;
Also, if these parameters are always coming in in the query string like you said, you are better off using $_GET
than $_REQUEST
Upvotes: 1
Reputation: 1502
$hike_id = isset($_REQUEST['hike_id']) ? $_REQUEST['hike_id'] : '0';
Upvotes: 1