I am currently following along in a text about PHP access to SQL DB's by Kevin Yank. I am running MYSQL 5.xx on a IIs 5 server in Win XP. My code in EXAMPLE 1 works fine when the $GET array is used to pass data. However, when the $POST array is used to pass data in EXAMPLE 2 the code does not work and I recieve many different errors, where the most common error is "... Undefined variable hostname ...", "... Undefined variable username ... ", etc. Also, the author claims that <?php ?> may be truncated to <?= ?> for short cut purposes. The code does not execute when the short cut method is used as described in example 3.

EXAMPLE 1.
///////////////THIS CODE WORKS:

FILE NAME>>welcome4.html
<html>
<form action="welcome4.php" method="get">
Hostname: <input type="text" name="hostname" /><br />
User Name: <input type="text" name="username" /><br />
Password: <input type="text" name="password" /><br />
<input type="submit" value="GO" />
</form>
</html>

FILENAME>>welcome4.php
<html>
<?php
$hostname = $GET['hostname'];
$username = $
GET['username'];
$password = $_GET['password'];
echo( "Welcome to my Website, $hostname $username $password!" );
?>
</html>

EXAMPLE 2
///////////////THIS CODE FAILS:
FILE NAME>>welcome4.html
<html>
<form action="welcome4.php" method="post">
Hostname: <input type="text" name="hostname" /><br />
User Name: <input type="text" name="username" /><br />
Password: <input type="password" name="password" /><br />
<input type="submit" value="GO" />
</form>
</html>

FILENAME>>welcome4.php
<html>
<?php
$hostname = $POST['hostname'];
$username = $
POST['username'];
$password = $_POST['password'];
echo( "Welcome to my Website, $hostname $username $password!" );
?>
</html>

EXAMPLE 3.
/////////////This code works:
<form action="<?php $_SERVER['PHP_SELF'] ?>" method="get">
<p>Type your joke here:<br />
<textarea name="joketext" rows="10" cols="40" wrap>
</textarea>
<br />
<input type="submit" name="submitjoke" value="Submit" />
</p>
</form>

///////////This code does not execute:
<form action="<?=$_SERVER['PHP_SELF']?>" method="get">
<p>Type your joke here:<br />
<textarea name="joketext" rows="10" cols="40" wrap>
</textarea>
<br />
<input type="submit" name="submitjoke" value="Submit" />
</p>
</form>

    If you're using IIS and you've got PHP installed as an ISAPI filter, it could be that IIS has limited the "verbs" that the PHP engine has access to. Make sure PHP has access to "All Verbs" in IIS.

    Also, do a phpinfo() and tell us the value for the variables_order, post_max_size, gpc_order, directive.

      The <? may only be used if an option short tags (I think) is enabled. This is not turned on by default and is frowned upon because it makes it difficult to embed XML processing instructions into an XML PHP document.

      $_POST should however always work. I recommend that you replace the custom script with one which simply executes phpinfo() to determine exactly which predefined variables are set.

      PHP and IIS do not always play nicely, it is entirely possible that IIS is configured to block POSTs to PHP.

      Mark

        1. Checked IIS settings
          [Application Config]:
          extension .php
          path c:\php\php5isapi.dll
          Verbs all

        [ISAPI Filters]
        status UP
        Name PHP
        Priority Unknown

        1. PHPinfo() results:
          variables_order EGPCS
          post_max_size 8M
          gpc_order //I could not find an entry for gpc_order in the results or in PHP.ini file.

        The PHPInfo() results are attached in a .pdf [107 kb] file that is in a .zip [93 kb] format due to 100k upload limit.

        ps: I recently purchased SUSE 10 to configure a dedicated linux box to this endeavor but due to current time constraints it will be a month or so before that will happen.

          Well that's certainly curious. Try using this code:

          <?PHP
          if(!isset($_GET['go'])) {
          ?><form method="post" action="<?PHP echo $_SERVER['PHP_SELF']; ?>?go=1">
          <input type="hidden" name="test" value="testing" /><input type="submit" name="button" value="Send" />
          </form><?PHP
          } else phpinfo();
          ?>

          Click the button, and re-attach the newly outputted phpinfo() page...

            The results using the code you suplied are in PHPInfo(2).pdf
            FYI:
            I modified the code you supplied by replacing $GET with $POST and the code does not execute [the submit page just remains with the button].
            When I first noticed this behaviour I reinstalled IIS and PHP [Manual install] to no avail.

              HyperP4 wrote:

              FYI: I modified the code you supplied by replacing $GET with $POST and the code does not execute [the submit page just remains].

              It should have been GET, because I used '?go=1' as the "action" of the form...

              At any rate it showed the post items just fine (under PHP Variables, the _POST[] stuff) so... is there a chance we can get a link to the HTML page of the form?

              Also, on the page that the form submits to, have you tried replacing everything with somethine like:

              print_r($_POST);

                I'm still puzzled... it's showing the POST'd variables in phpinfo() just fine...

                Try this:

                <?PHP 
                if(!isset($_GET['go'])) { 
                ?><form method="post" action="<?PHP echo $_SERVER['PHP_SELF']; ?>?go=1"> 
                <input type="hidden" name="test" value="testing" /><input type="submit" name="button" value="Send" /> 
                </form><?PHP 
                } else print_r($_POST); 
                ?> 

                  Is it possible that ths is not an issue with the code but more with my browser. I realize that PHP executes on the server and then renders the webpage which should eliminate my browser [IE 6] being an issue. When you use this link does it seem to work for you? It fails when I execute it: "... undefined variables..."
                  http://hyperp4.mine.nu/welcome4.htm

                  Here is the last code you posted.
                  http://hyperp4.mine.nu/print.php

                    The pages work with Firefox 1.5 and IE6 with XP sp2, don't know what is going on with your browser.

                      Thanks for your help with this issue!

                        I had the same problem. I fixed it by changing my php installation from CGI binary to the ISAPI module.

                          Write a Reply...