edwardda Posted May 10, 2013 Share Posted May 10, 2013 Can someone please help > im new to php and trying to complete code for a tour price calculator and keep getting the following error message Undefined index: error in C:\wamp\www\tourprice.php on line 32 line 32 reads 32 if ($_GET['error'] == "notnumeric"){ 33 echo "<p class=\"error\">*** Error! One or more fields was left blank or contained a non-numeric character.</p>";34 } ?> any help would be greatly appreciated Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted May 11, 2013 Share Posted May 11, 2013 if $_GET['error'] is optional (may or may not exist), you need to first test if it is set before you test the value in it. if(isset($_GET['error']) && $_GET['error'] == "notnumeric"){ if it's not optional and you expect it to always be present, you should probably troubleshoot why it isn't present. if you are are testing that variable against more than about one value/error message, you should reduce the amount of logic needed to only one set and lookup the value using an array that maps the incoming text string to the actual message - $error_lookup['notnumeric'] = "*** Error! One or more fields was left blank or contained a non-numeric character."; // add other error names/error messages here $error = isset($_GET['error']) ? strtolower(trim($_GET['error'])) : ''; if(!empty($error)){ if(isset($error_lookup[$error])){ echo "<p class='error'>$error_lookup[$error]</p>"; } else { // bad value echo "<p class='error'>An undefined error ($error) was triggered.</p>"; } } Quote Link to comment 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.