Jump to content

Recommended Posts

I'm using $_POST[] and $_SESSION[] arrays for a homemade quiz.

When I turned display errors on in my PHP file I got alot of "undefined array" errors for those ones.

Is there anyway I can allow those two variables to be undefined? Like, everything is working fine and I've accounted for them beeing NULL at times.

Link to comment
https://forums.phpfreaks.com/topic/315434-undefined-arrays/
Share on other sites

8 minutes ago, Niss3 said:

Is there anyway I can allow those two variables to be undefined?

You should ensure they are not undefined before attempting to use them.

In the case of $_SESSION, call session_start() at the head of any script requiring $_SESSION.

In the case of $_POST, check if data was posted to the script

if ($_SERVER['REQUEST_METHOD'] == 'POST' ) {
    // safe to use $_POST here
}

 

Link to comment
https://forums.phpfreaks.com/topic/315434-undefined-arrays/#findComment-1601748
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.