PHP error: Notice: Undefined index:

后端 未结 14 1554

I am working on a shopping cart in PHP and I seem to be getting this error \"Notice: Undefined index:\" in all sorts of places. The error refers to the similar bit of coding

14条回答
  •  温柔的废话
    2020-12-03 15:45

    I did define all the variables that was the first thing I checked. I know it's not required in PHP, but old habits die hard. Then I sanatized the info like this:

    if ($_SERVER["REQUEST_METHOD"] == "POST") {
      if (empty($_POST["name1"])) {
        $name1Err = " First Name is a required field.";
      } else {
          $name1 = test_input($_POST["name1"]);
        // check if name only contains letters and whitespace
          if (!preg_match("/^[a-zA-Z ]*$/",$name1)) {
          $name1Err = "Only letters and white space allowed";
    

    of course test_input is another function that does a trim, strilashes, and htmlspecialchars. I think the input is pretty well sanitized. Not trying to be rude just showing what I did. When it came to the email I also checked to see if it was the proper format. I think the real answer is in the fact that some variables are local and some are global. I have got it working without errors for now so, while I'm extremely busy right now I'll accept shutting off errors as my answer. Don't worry I'll figure it out it's just not vitally important right now!

提交回复
热议问题