Implementing search I get: Undefined variable: query

This is strange. On MacOS MAMP page loads no problem. On Windows MAMP with the exact same files page fails to load with: Undefined variable: query

<form>
<input type="search" name="q" value="<?php echo esc($query) ?>">
<input type="submit" value="Search">
</form>

I have to define $query to get it to work.

value="<?php $query = ""; echo esc($query) ?>"

Can anyone shed some light on why this might be happening? Maybe MacOS MAMP is more error tolerant?

Thanks

You can check if $query is defined instead:

isset($query)? esc($query):'';

It depends on your PHP error settings in php.ini what is shown as error and what is not.

http://php.net/manual/de/function.error-reporting.php

2 Likes