Niss3 Posted October 18, 2022 Share Posted October 18, 2022 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. Quote Link to comment https://forums.phpfreaks.com/topic/315434-undefined-arrays/ Share on other sites More sharing options...
ginerjm Posted October 18, 2022 Share Posted October 18, 2022 You'll have to show us the code where the errors are pointing. Be sure to clearly identify them to us. Quote Link to comment https://forums.phpfreaks.com/topic/315434-undefined-arrays/#findComment-1601747 Share on other sites More sharing options...
Barand Posted October 18, 2022 Share Posted October 18, 2022 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 } Quote Link to comment https://forums.phpfreaks.com/topic/315434-undefined-arrays/#findComment-1601748 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.