Lecture Notes Eleven: Competing server-side technologies.

In lab tomorrow you will install PHP.

In class today we need to talk about what you have to turn in tomorrow.

So we will discuss briefly CGI.pm, but not much.

We then look at the lab for tomorrow, and go through a set of examples.

Let's start with this one:

#!/u/dgerman/php-install/bin/php

<html><head><title>This is my portfolio</title></head><body bgcolor=white>

<? echo $QUERY_STRING ?> <p> 

<table width=100% cellpadding=2>

<tr> <td align=center> 

<? if ($QUERY_STRING == "seven") {

     echo "Lindley 07";

   } else {

     echo "<a href=\"$SCRIPT_NAME?seven\">Lindley 07</a>"; 

   }

 ?>
     </td> <td align=center> 

Lindley 08

     </td> <td align=center> 

Lindley 01

     </td> <td align=center> 

Lindley 09

     </td> 
</tr>
<tr> <td colspan=4 align=center>

  <? if ($QUERY_STRING == "seven") {
       echo 
            "<img src=\"http://www.cs.indiana.edu" . 
            "/dept/img/lh07.gif\">"; 
     } else {
       echo 
            "<img src=\"http://www.cs.indiana.edu" . 
            "/l/www/classes/a202-dger/sum99/a202.gif\">"; 
     }
  ?>

</td> 
</tr>
</table>

</table>

</body>
</html>
Does it remind you of anything?

Can you finish it?

Does it feel different, when developing it?

Let's look at another example.

<html><head><title>Bob's Auto Parts</title></head><body bgcolor="white">

<h1>Bob's Auto Parts</h1>

<h3> Order Form</h3>

<form action="/php3/processOrder.php3" method="post">

<table border=0>

<tr bgcolor="#cccccc">
  <td width=150> Item </td>
  <td width=15>Quantity</td>
</tr>

<tr> 
  <td>Tires</td> 
  <td align=center><input type="text" name="tireqty" size=3 maxlength=3></td>
</tr>

<tr> 
  <td>Oil</td> 
  <td align=center><input type="text" name="oilqty" size=3 maxlength=3></td>
</tr>

<tr> 
  <td>Spark Plugs</td> 
  <td align=center><input type="text" name="sparkqty" size=3 maxlength=3></td>
</tr>

<tr> 
  <td colspan=2
      align=center><input type="submit" value="Submit Order"></td>
</tr>
</table>

</form>

</body>
</html>
Try it here.

How's the processOrder script look like?

#!/u/dgerman/php-install/bin/php

<html><head><title>Order Results</title></head><body bgcolor="white">

<h1> Bob's Auto Parts</h1>

<h3>Order Results</h3>

<?
    echo "Thank you for your order!"; 
 ?>

</body>
</html>
Let's develop it a bit.

#!/u/dgerman/php-install/bin/php

<html><head><title>Order Results</title></head><body bgcolor="white">

<h1> Bob's Auto Parts</h1>

<h3>Order Results</h3>

<?

    $tireqty += 0; 
    $oilqty += 0; 
    $sparkqty += 0; 

    echo $tireqty . " tires <br>" . 

         $oilqty . " bottles of oil <br>" . 

         $sparkqty . " spark plugs <p>" ; 

    if ($tireqty >= 0 && 
        $oilqty  >= 0 && 
        $sparkqty >= 0 && 
        ($tireqty + $oilqty + $sparkqty > 0) ) {
     
      echo "Thank you for your order!"; 

    } else {
  
      echo "This is not a valid order. "; 

    }
 ?>

</body>
</html>
Which makes the next move almost inevitable.

What does this bring to mind?

#!/u/dgerman/php-install/bin/php
<html><head><title>Bank Accounts</title></head><body bgcolor="white">

<? if ($fun == "add") {
     $acc += $arg; 
   } else if ($fun == "sub") {
     $acc -= $arg; 
   } else {

   }
 ?>

Current accumulator is: <? echo $acc ?>

<form method="post" action="<? echo $SCRIPT_NAME; ?>">

Amount: <input type="text" name="arg"> <p> 

Action: <select name="fun">
  <option value="non"> Click Me!
  <option value="add"> Deposit
  <option value="sub"> Withdraw
</select> <p> 

<input type="hidden" name="acc" value="<? echo $acc; ?>">

Fill in the form then push: <input type="submit" value="Proceed">

</form>

</body></html>
How does it work?

Well, here's the last part of the side by side comparison.

#!/u/dgerman/php-install/bin/php
<html><head>Showing Books</title></head><body bgcolor="white">
  <? 
      echo "Howdy! <p> "; 

      $db = mysql_connect("localhost", "a348", "a348AG") 
         or die ("Could not connect"); 

      print "Connected successfully. <p>"; 

      mysql_select_db("a348"); 

      $query = " select * from dgerman_BOOKS "; 

      $result = mysql_query($query); 

      $num_results = mysql_num_rows($result); 

      echo "<p> Number of books found: " . $num_results . "<p>"; 

      for ($i = 0; $i <  $num_results; $i++) {

        $row = mysql_fetch_array($result); 

        echo "<img src=\"http://www.cs.indiana.edu" . 
             "/classes/a114/fall2001/lectures/nine" . 
             "/" . $row["isbn"] . ".jpg\"> "; 

      }

   ?>

</body>
</html>

</body></html>
Here's how it works.

Now, at least, we can compare the two methods.


Last updated: Oct 2, 2001 by Adrian German for A348/A548