ok well this is my problem, i have a form with two checkbox's on page "A" and my action submits the values of the form to page "B" when this happens i get the error :

Notice: Undefined variable: (the variable name and location)

i have defined the var naming it "x" and in my if statment i call the variable with $x, my record_global setting in my php.ini file is set to "On" so i am very sure it is not that.

the tricky thing is if i check the boxes i dont get the error so it is as if there is no value in the box unless you check it so i set a value to it, first i set its value to " ", then i set it to "Off" nothing works, i really dont know what the problem is.

can someone plz help meπŸ˜•

    How are you reading the information in page b?
    You could try
    $x = $_POST["x"];

      Check boxes only get posted if they have been checked. That's why the error goes away when the box is checked. Even with register globals on you should probably still use $_POST so

      $box = $_POST['x'];
      if ($box != null)
      {
      / Process it /
      }

      Or you could use isset
      if (isset($x))
      {
      / Process it /
      }

        hey dude,

        thanx for the reply and although it didnt work i have learnt something new i inserted the code :

        $box = $_POST['x'];

        if ($box != null) {

        /* Process it */

        }

        and then i get the error :

        Notice: Undefined index: ( variable name ( being x) and location ), but it is refering to the page i had the form on, so i think the problem is with the other page, this is really frustrating!!!

        i really do appreciate your help.
        πŸ™‚

          You can just ignore those notice messages coz form my experience, it affects no parts of your script execution. So, shut it off by declaring:

          error_reporting(0);

          If you are still want to receive some error, just adjust it to suit your needs.

            You can get rid of the warning with something like:
            if (isset($POST['x'])) $x = $POST['x'];
            else $x = null;

            You can suppress these warnings as scoppc suggests but they can be very useful for detecting
            spelling errors. I would suggeest you keep them turned on.

              Bad idea to simply ignore errors of any kind, good idea to understand their meaning.

              First you must realize that only checked checkboxes pass name/value pairs as unchecked checkboxes pass nothing to PHP. That said, the variable will only be set if the checkbox is checked.

              Assuming you have two checkboxes each being named x (btw, consider using a radio button or better explain the problem), follow ahundiak's second advice and try this:

              <?php
              if (isset($x)) {
                  echo "This checkbox named x was checked, its value is: $x";
              } else {
                  echo "The checkbox was not checked";
              }
              ?>
              

              The error you got was because it was unchecked so you were using a variable that didn't even exist. Not a major deal, you could simply ignore it, but please consider not ignoring it.

              Also, consider not relying on register_globals and instead using a superglobal.

              P.S. During my last preview of this post I notice that ahundiak just posted something, well, I'll post this too πŸ™‚

                Ignoring NOTICE should be okay. Yeah, I do agree not ignoring such error is better. However, during my scripting, I wouldnt wanna spend my time to keep setting the variable or check whether it has been set just to get rid of the notice. hehe... at least, I dont think it's important.

                WARNING and PARSE ERROR are important (some times I ignored WARNING too). πŸ™‚
                In a testing server, just turn everything on. Helpful to debug your application. But in a production server, never ever left it on. Hide all error messages by using error_reporting(0) and maintain a good log file on the errors so that you can review it personally.

                User will scare to see the NOTICE or WARNING or PARSE ERROR. Believe me!

                  Write a Reply...