Previous   -   Index   -   Next  >


First Example


first.php

The XHTML markup....

<form action="first.php" method="post"><p>
Please enter your name: 
<input type="text" name="userName"/><br /><br />
and press one of these buttons 
<input type="submit" name="button" value="A"/>
<input type="submit" name="button" value="B"/>
</p></form>

...creates the following form...

Please enter your name:  

and press one of these buttons    

first.php contains the following:

<?php echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"; ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/tr/xhtml1/DTD/xhtml11.dtd" >
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-gb">
<head>
<title>A first PHP example</title>
</head>
<body>
<h1>Welcome <?php echo $_POST['userName'] ?></h1>
<p>
I see that you are using a browser type:<br />
 &nbsp; &nbsp; <?php echo $_SERVER['HTTP_USER_AGENT'] ?><br />
from IP address: <?php echo $_SERVER['REMOTE_ADDR'] ?>
<p></p>
<?php
if ( isset($_POST['button']) ) echo 'You pressed button ' . $_POST['button'];
?>
</p>
</p>
</body>
</html>

Things to note about first.php:


Quick Question

What is the difference between

  1. echo "$userName = " . $userName;
  2. echo '$userName = ' . $userName;


Previous   -   Index   -   Next  >

best viewed using Mozilla browsers
© k.mcmanus 2004
Valid XHTML 1.! . Valid CSS . WCAG priority 3 approved