GeekedOut
GeekedOut

Reputation: 17185

How to stop a page from returning a 500 error

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

Answers (3)

Will Warren
Will Warren

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

safarov
safarov

Reputation: 7804

Use isset() to check variable is set

Upvotes: 1

rainecc
rainecc

Reputation: 1502

$hike_id = isset($_REQUEST['hike_id']) ? $_REQUEST['hike_id'] : '0';

Upvotes: 1

Related Questions