Jump to content

Undefined index: error in C:\wamp\www\tourprice.php on line 32


edwardda

Recommended Posts

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

Link to comment
Share on other sites

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>";
    }
}
Link to comment
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.