cunoodle2 Posted May 21, 2009 Share Posted May 21, 2009 I'm going through all of my pages now doing final work turned on error reporting to see if I was missing anything. I put this code at the top of my pages.. <?php //print errors to screen... ini_set ("display_errors", "1"); error_reporting(E_ALL); ?> The produced the error message.. Notice: Use of undefined constant submit - assumed 'submit' in /home/website/public_html/NewUser.php on line 48 Line 48 is this.. <?php if (isset($_POST[submit])) ?> Should I have structured this differently? Is there a way that I could be handling the form submission in a more secure way? Link to comment https://forums.phpfreaks.com/topic/159157-solved-notice-use-of-undefined-constant-submit/ Share on other sites More sharing options...
PFMaBiSmAd Posted May 21, 2009 Share Posted May 21, 2009 Array index names are strings - <?php if (isset($_POST['submit'])) ?> Link to comment https://forums.phpfreaks.com/topic/159157-solved-notice-use-of-undefined-constant-submit/#findComment-839344 Share on other sites More sharing options...
radi8 Posted May 21, 2009 Share Posted May 21, 2009 This $_POST value was probably inside another if statement and may not have been executed (prior if returned false or something). What you may want to do is assign the $_POST value to a static variable in an area of your code that is triggered by any page load and then reference that variable in the line 48 statement. Link to comment https://forums.phpfreaks.com/topic/159157-solved-notice-use-of-undefined-constant-submit/#findComment-839346 Share on other sites More sharing options...
cunoodle2 Posted May 21, 2009 Author Share Posted May 21, 2009 Array index names are strings - <?php if (isset($_POST['submit'])) ?> Since they are stating that "submit" was undefined can I somehow set the index name of the array without overwriting the contents of it or am I just worrying too much about a notice message on the page? This $_POST value was probably inside another if statement and may not have been executed (prior if returned false or something). What you may want to do is assign the $_POST value to a static variable in an area of your code that is triggered by any page load and then reference that variable in the line 48 statement. This actually is the very first "if" statement on the page. Is there a better more secure way to check to see if a form was submitted? Link to comment https://forums.phpfreaks.com/topic/159157-solved-notice-use-of-undefined-constant-submit/#findComment-839356 Share on other sites More sharing options...
PFMaBiSmAd Posted May 21, 2009 Share Posted May 21, 2009 When you don't put array index name strings inside quotes, php must first loop up the name in the list of all the defined constants, both the built in and any user defined. When it does not find a match, it must handle the resulting error. Unfortunately, in php's infant day php.net made an poor decision that when an undefined constant is found, that it would "help" the programmer by assuming (i.e. to make an ASS out of U and ME) that he actually meant to put quotes around the name. Php then generates the error message posted and then searches again for the index name with quotes around it this time. If it finds that array index it accesses the value. The fun part of all this is that this whole process takes 8 to 10 times longer to execute the line of code with no quotes around the index name, every time it is executed, than what would take to execute that line if it had the proper quotes around the name string. Link to comment https://forums.phpfreaks.com/topic/159157-solved-notice-use-of-undefined-constant-submit/#findComment-839359 Share on other sites More sharing options...
PFMaBiSmAd Posted May 21, 2009 Share Posted May 21, 2009 Since they are stating that "submit" was undefined .... No it isn't. Please read the fricking error message. It says: Use of undefined constant submit - assumed 'submit' Link to comment https://forums.phpfreaks.com/topic/159157-solved-notice-use-of-undefined-constant-submit/#findComment-839361 Share on other sites More sharing options...
DarkSuperHero Posted May 21, 2009 Share Posted May 21, 2009 ....meaning....you need to specify a key with quotes... like PFMaBiSmAd said the first time around.... $_POST is an array, with all your form values....'submit' being a key, and the value would be anything inside "value" attribute or inside the actual input field.... Link to comment https://forums.phpfreaks.com/topic/159157-solved-notice-use-of-undefined-constant-submit/#findComment-839375 Share on other sites More sharing options...
cunoodle2 Posted May 21, 2009 Author Share Posted May 21, 2009 When you don't put array index name strings inside quotes, php must first loop up the name in the list of all the defined constants, both the built in and any user defined. When it does not find a match, it must handle the resulting error. Unfortunately, in php's infant day php.net made an poor decision that when an undefined constant is found, that it would "help" the programmer by assuming (i.e. to make an ASS out of U and ME) that he actually meant to put quotes around the name. Php then generates the error message posted and then searches again for the index name with quotes around it this time. If it finds that array index it accesses the value. The fun part of all this is that this whole process takes 8 to 10 times longer to execute the line of code with no quotes around the index name, every time it is executed, than what would take to execute that line if it had the proper quotes around the name string. Thank you for pointing all of that out to me. I missed the single quotes in your original response at the beginning of the forum. I had no idea that it took 8-10 times longer and I will say that is probably one of the best things I've learned on this forum in order to help me speed up page processing times a little. I know we are talking micro seconds but every little bit helps and I GREATLY appreciate it. Link to comment https://forums.phpfreaks.com/topic/159157-solved-notice-use-of-undefined-constant-submit/#findComment-839399 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.