The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End Drop Down Executes Query On Post? Reply To: Drop Down Executes Query On Post?


Without strict Error filtering they work! I was previously using :

Ah. No, they weren’t “working.” You were just ignoring the error messages.

E_ERROR means you only want to pay attention to Fatal Errors. Undefined variables are reported at the E_NOTICE level, so you didn’t see them. Same thing with your Warning about the fetch function: that’s E_WARNING, which you had been ignoring.

I can get rid of the error messages :
[changing] $message = $_GET['message'];
to :
(!empty($_GET['$message']) ? $_GET['$message'] : null);

That’s how you do it.
You could also do:

$message = isset( $_GET['message'] )? $_GET['message']: "";

isset because it is faster than !empty, and "" instead of null because you expect the var to hold a string (though this second part won’t cause problems either way).

I use the message variable to display empty form field validation messages… So I tried removing it from within the HTML and declaring it inside the php (at the top of the page) as follows :

You don’t need to move the echo statement. That should stay at the point where you want the variable to be printed. In your php section, just make sure the $message is defined no-matter-what (i.e., even if there is no message to show). For example, if you have something like this:


if( $INeedToSendAMessage ){
    $message = "Hello, World!";
echo $message;

$message will be undefined if you don’t need to send a message, but you try to echo it no-matter-what. So, make sure $message is defined no-matter-what:


$message = "";

if( $INeedToSendAMessage ){
    $message = "Hello, World!";
echo $message;

why it may appear as if the variables are not being used, I’ve copied a page as a template …

Which is fine. Just make sure they are defined with default/empty values, and it’ll be fine.

If you end up with a variable that will never be used on your page, however, it is best to simply remove it before you are done.

You can post from the gist. I’ve updated it to show the changes.

It is still marked secret, so I can’t fork it (you would need to change it to public). I can copy it manually, though. Just wanted to make sure it was okay.