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>