PHP Lab #4: Simple forms

  1. In Notepad, create a new HTML file called phplab4.html. Insert the following HTML code, which creates a form.

    <HTML>
    <HEAD>
    <TITLE>PHP lab 4 </TITLE>
    </HEAD>
    <BODY>
    
    <FORM ACTION="phplab4_result.php" METHOD="POST">
    Enter a number: <BR>
    <INPUT TYPE="TEXT" NAME="yournumber"><BR>
    <INPUT TYPE="SUBMIT" VALUE="Go"><BR>
    </FORM>
    

  2. View phplab4.html in your web browser. You should see a spot for entering in a number, and a "Go" button.

  3. Experiment with the above HTML by selectively removing lines and seeing what happens. Answer the following questions:

  4. Type a number into the box, then click the "Go" button. You should receive an error message. Answer the following question:
  5. Now create in Notepad a new file called "phplab4_result.php", and enter into it the following:

    
    <HTML>
    <HEAD>
    <TITLE>PHP lab 4 results </TITLE>
    </HEAD>
    
    <BODY>
    <?php
    	print("Here is your number: $yournumber <BR>");
    	$square = $yournumber*$yournumber;
    	print("Here is your number squared: $square <BR>");
    ?>
    
    </BODY>
    </HTML>
    

  6. Now try your phplab4.html web page again, type in a number, then click the "Go" button. If all goes correctly, you should see a new web page that does some calculations based on your numbers.

  7. Here is a final exercise:


Page by Michelle Phillips, Jeff Ondich, and Dave Musicant. Last updated 10.03.02