0) { $stage--; } if (!empty($next) && $stage < $last_stage) { $stage++; } $Today = date("D M d H:i:s T Y"); $colors = array ("Red", "Orange", "Yellow", "Green", "Blue", "Indigo", "Violet"); ?> <?php print $title; ?> >
?>
- home - source code -


"; print "

Introduction

"; print "PHP is a server-side, cross-platform, HTML embedded scripting language.

"; print "PHP uses PERL style variables (scalars, arrays, and hashes) but its syntax is more like C.

"; print "PHP binaries and source code can be downloaded from http://www.php.net. It is free for personal and commercial use.

"; print "PHP is simple enough for casual web pages and powerful enough for ecommerce sites."; print "

"; print "A small sample program:


"; $example = " <?php echo \$title; ?> A list of PHP advantages:

    \$item\"; } ?>
"; print "
";
                  print htmlspecialchars( $example );
                  print "
"; break; case 1: print "

$stage. Dynamic HTML

"; print "PHP can be used to customize simple things such as background colors to very complex things such as inventory lists (pulled from a database).

"; print "PHP can preserve a certain look and feel throughout a web page while changing the content.

"; print "PHP can produce HTML or be used as a device to display static HTML files.

"; print "

Examples:

"; print "Current date/time: $Today

"; print "Change background color to:
"; print ""; for ($index = 0; $index < count ($colors); $index++) { print ""; } print "
"; print ""; print "$colors[$index]
"; print "

"; break; case 2: print "

$stage. Form Processing

"; print "
  • PHP can process information from a plain HTML form or one that is generated by PHP.

    "; print "
  • Each HTML form field is turned into a PHP variable with the same name.

    "; print "
  • Once the form variable is in PHP it can be manipulated like any other variable. Information can be stored in a datbase, checked for errors, used to generate an email, etc.

    "; print "

    Example:

    "; if (!empty($form_example)) { print "Your email is: $form_example
    "; print "Your favorite color is: $fav_color.

    "; if (empty($fav_color)) { $fav_color = "(unspecified)"; } $msg = "PHP Example\n\n"; $msg .= "Your email is: $form_example\n"; $msg .= "Your favorite color is: $fav_color.\n\n"; $recipient = "$form_example"; $subject = "PHP Example"; $mailheaders = "From: The Computer Club <> \n\n"; mail($recipient, $subject, $msg, $mailheaders); } print "Email:
    Favorite Color:
    "; print ""; for ($index = 0; $index < count ($colors); $index++) { print ""; } print "
    "; print ""; print "$colors[$index]
    "; print "

    "; break; case 3: print "

    $stage. Files

    "; print "PHP can open, display, read, write, and otherwise manipulate files.

    "; print "A file can be a local file or a URL

    "; print "Reading files is very easy but writing to files can only be done under special circumstances. It is generally very insecure to allow a web-based application to write to files. If it is necessary to store information, a database provides a much more secure (and powerful) interface.

    "; print "

    Example:

    "; $file = fopen("text.txt", "r"); print "
    ";
                      fpassthru($file);
                      print "
    "; print "
    Output from a text file
    "; break; case 4: print "

    $stage. Database Access

    "; print "PHP can connect to PostgreSQL and MySQL databases. PHP also supports Oracle, Informix, Microsoft SQL Server, Sybase, and ODBC database connections.

    "; print "PHP can perform all standard SQL operations by passing an SQL statement to a database execute command.

    "; print ""; print "

    Example:

    "; if(!$connection = @mysql_connect("MYSQL_HOST","MYSQL_USERNAME","MYSQL_PASSWORD")) { print "Cannot connect to database engine."; } if(!$db = @mysql_select_db("DB_NAME", $connection)) { print "Database not found"; } /* print "
    "; print "

    "; if (!empty($data)) { $DateTime = date("Y-m-d H:i:s"); $sql = "insert into data (name, date) values ('$data', '$DateTime')"; if (!($sql_result = mysql_query($sql,$connection))) { print "Couldn't execute query - $sql
    "; } } */ if (empty($order)) { $order = "id"; } $sql = "select * from info order by $order"; if (!($sql_result = @mysql_query($sql,$connection))) { print "Couldn't execute query - $sql
    "; } print ""; print ""; print ""; print ""; $tr_color="orange"; while ($row = @mysql_fetch_array($sql_result)) { print ""; print ""; print ""; print ""; if ($tr_color=="orange") { $tr_color="white"; } else { $tr_color="orange"; } } print "
    ".$row["id"]." ".$row["name"]." ".$row["date"]."
    "; @mysql_free_result($sql_result); mysql_close($connection); break; case 5: print "

    $stage. Additional Information

    "; print "

      Other PHP Functions

      "; print "
    • Graphics manipulation
    • Regular Expressions"; print "
    • Cookies"; print "
    • Execute shell commands"; print "

      Links

      "; print "
    • http://www.php.net - PHP Homepage"; print "
    • http://www.thickbook.com - PHP Tutorials"; print "

      Recommended Text

      "; print "
    • Professional PHP Programming
      Castagnetto, et al
      Published by WROX"; print "
    "; break; case $last_stage: print "


    "; print "

    Questions?

    "; break; } ?>
  • >