I'm running IIS on Win XP with latest mysql and php5.

I'm attempting to set up the login example:

http://www.phpbuilder.com/columns/tim20000505.php3

and I'm getting the following error messages:

Notice: Undefined variable: submit in c:\Inetpub\wwwroot\register.php on line 12

Notice: Undefined variable: feedback in c:\Inetpub\wwwroot\register.php on line 18

Notice: Undefined variable: PHP_SELF in c:\Inetpub\wwwroot\register.php on line 31

Notice: Undefined variable: real_name in c:\Inetpub\wwwroot\register.php on line 33

Notice: Undefined variable: email in c:\Inetpub\wwwroot\register.php on line 45

I'm thinking it has something to do with the face that this is old php, and the code hasn't been updated for php5.

THanks guys.

Andrew

    It has nothing to do with PHP5 specifically. Just use isSet(). Read on for a full explanation.

    Sample code:

    $first_name = $_REQUEST['first_name'];

    The above code example would generate the following type of notice message only when the error_reporting() allows E_NOTICE type of messages (error_reporting is also a php.ini setting):

    Notice: Undefined index: first_name in …

    Some people are surprised by these notices and think they are out right errors; and they perhaps didn't see the notices when they were testing on their local machine, but see them on their web host providers server (or vice versa). That's because of the difference in 'error_reporting' settings between the two servers. This type of notice messages means that there doesn't seem to be an index entry with 'first_name' and so PHP considers it undefined. One way to prevent this notice is to not assume that an array index is there and check for it specifically first using the isSet() function as in this example:

    $first_name = isSet($_REQUEST['first_name']) ? $_REQUEST['first_name'] : '';
    

    This uses the ternary comparison operator. The $first_name variable will be assigned the value of $_REQUEST['first_name'] if it contains something other than NULL. Otherwise, it will be initialized to an empty string (you can set this to be anything you want as a default).

    While testing scripts, I recommend that you have the E_NOTICE type of error messages on to help find possible problem areas in your code. Then turn it off before using scripts in a production setting.

    Also, this example of code:

    $name .= 'Doe'; 

    Will produce the following notice message:

    Notice: Undefined variable: name in …

    The '.=' is concatenating the 'Doe' to the existing value found in $name. Since the $name variable has not been initialized to something first you may get unpredictable results. Make sure you set/initialize all variables before using the '.=' concatenation assignment. The following code example will not produce the notice since a straight equal assignment is used before the use of '.=':

    $name = 'Jane ';
    $name .= 'Doe';
    echo $name;   // Displays Jane Doe
    

      Toplay - thanks a ton, that worked. I was looking at the code and that struck me as it might be the problem, but I'm too much of a noob at php..haha.

      Yeah I was doing some research and it stikes me that turning register_globals ON is not a good idea. Right now I'm testing on my local machine, so who cares, but eventually it's goin on the web. How would I replace the PHP_SELF with $GET or $POST? In this code i guess it's just using it to find the http info?

      Also, another question is this code uses $DOCUMENT_ROOT, which doesn't seem to be working. I tried echoing it but it has the same error. Is this something that's part of PHP or is a variable that the programmer defined somewhere and I need to change for my particular use?

      EDIT: I tried echo $_SERVER['DOCUMENT_ROOT']; on an actual webserver on the web and it worked, however it doesn't work on my local machine. Maybe something in my php.ini file?

      Thanks guys.

      Andrew

        $PHP_SELF and $DOCUMENT_ROOT would be created if register_globals are on. So, instead use $SERVER['PHP_SELF'] and what you have of $SERVER['DOCUMENT_ROOT']. Mine, on Windows shows:

        C:/Program Files/Apache Group/Apache2/htdocs

        I do have in my php.ini file this set:
        doc_root = "C:/Program Files/Apache Group/Apache2/htdocs"

        FYI - PHP manual page on $_SERVER and other predefined variables:
        http://us3.php.net/reserved.variables#reserved.variables.server

        hth.

          2 years later

          Problem of PHP,
          Output of my PHP gives the following;
          When i write my code on my HTMl like;
          <form action="welcome3.php"method="get">
          <label>First Name: <input type="text" name=firstname" />
          </label><br />
          <label>Last Name; <input type="text" name="lastname" />
          </label><br />
          <input type="submit" value="GO" />
          </form>

          and create the return page with the php code

          <?php
          $firstname =$POST( 'firstname' );
          $lastname = $
          POST( 'lastname' );
          echo "Welcome to our Website, $firstname $lastname!";
          ?>

          i then put the two files in my C:\Inetpub\wwwroot\ folder
          on loading the page and
          When you fill the data on the welcome3.html page and hit the GO Button
          i expect to receive a response such as;
          welcome to our Website,First name Last Name
          ...Instead it gives me this response

          Fatal error: Function name must be a string in C:\Inetpub\wwwroot\welcome3.php on line 10

          Where do you think the problem comes from?my server(i use IIS) or my php manual documentation?
          I need help?

            Use square brackets for your array indexes, not parentheses, e.g.: $_POST['firstname']

              Dear Nog dog,
              Thanks for your assistance.It worked

              $firstname =$POST[ 'firstname' ];
              $lastname = $
              POST[ 'lastname' ];

              Now it works but the problem is that instead of giving the first name and last name the browser response gives back only the last name like;
              Welcome to our Website, Dog!
              instead of Welcome to our Website, Nog Dog!
              it doesn't output the first name Nog

              The same when i use this code below;

              p>Today's Date(according to this web server) is
              <?php

              echo date(', F dS Y. ');

              it doesnt give me the day instead it appears this way on the server;

              Today's Date(according to this web server) is , April 17th 2007

              You see the space before April,a day of the week is supposed to be there but its not there

              am i ommitting something somewehere in the code or is it from the server??

              John

                You are omitting the desired format character before the comma in the string your provided as as argument to the [man]date/man function.

                  5 days later

                  You also have a missing quote in your HTML (before firstname).

                  Also, when posting PHP code, please use the board's [PHP][/PHP] bbcode tags - they make the code much, much easier to read (as well as aiding the diagnosis of syntax errors). You should edit your post now and add these bbcode tags to help others in reading/analyzing your code.

                    Write a Reply...