Client/Server w/PHP

PHP and JSP are very similar and generally serve the same purpose within a web application architecture. PHP is a high level interpreted scripting language. What this means in the bottom line is that it is often easier to write dynamic web pages in PHP. Also PHP which stands for Personal Home Page was specifically written for authoring dynamic web pages. Java on the other hand is a more low level general purpose programming language.

Most internet service providers (ISP) including Yahoo, godaddy, etc. will provide you with both php scripting and MySQL database access. So with your typical $5/mo account you have all you need to go live with a PHP/MySQL site.

The develop on your Windows PC, you can download a product for free called XAMPP, that is what we will use tonight. It comes from the acronym: LAMP which stands for Linux, Apache, MySQL, and PHP. XAMPP stands for Cross-platform Apache, MySQL, PHP and/or Perl. This tools provides a local working version of the entire nTier architecture above. See Wikipedia for more information and to download:

Once you install it you will have the entire architecture, but if you already have MySQL installed you really only needs to start the apache services. All source files for php will be found in:

[XAMPP_ROOT]\xampp\htdocs. The [XAMPP_ROOT] is a place holder for wherever you installed. You probably also want to create some sub-directories for your php files:

You can use a tool like Netbeans to develop php any editor/file manager, such as the Windows file manager and notepad++

Phpinfo.php:

<?php

phpinfo();

?>


Php1.php:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"

"

<!-- Fig. 23.1: first.php -->

<!-- Simple PHP program. -->

<html xmlns = "

<?php

$name = "Harvey"; // declaration and initialization

?<!-- end PHP script -->

<head>

<title>Using PHP document</title>

</head>

<body style = "font-size: 2em">

<p>

<strong>

<!-- print variable name’s value -->

Welcome to PHP <?php print("$name");?>

</strong>

</p>

</body>

</html>


PHP actually has three different ways of connecting to databases. The latest is a very modern JDBC like way called PDO and generically available to most databases. The original way was hard coded to assuming MySQL always as the database. There is a hybrid approach between the two that most people prefer to use because it performs the best. I will point out all three methods to.

<?php print( '<?xml version = "1.0" encoding = "utf-8"?>' ) ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"
<!-- Fig. 23.22: formDatabase.php -->
<!-- Displaying the MailingList database. -->
<html xmlns = "
<head>
<title>Search Results</title>
<style type = "text/css">
body { font-family: arial, sans-serif;
background-color: #F0E68C }
h3 { color: blue }
table { background-color: #ADD8E6 }
td { padding-top: 2px;
padding-bottom: 2px;
padding-left: 4px;
padding-right: 4px;
border-width: 1px;
border-style: inset }
</style>
</head>
<body>
<?php
extract( $_POST );
// build SELECT query
$query = "SELECT * FROM contact_info";
// All variables in PHP start with a $ and do not need to be typed or declared.
// In Java/jsp the declaration would look like: String query = “SELECT * FROM...”;

// Connect to MySQL
$mysqli = new mysqli("localhost", "", "", "test");
if (mysqli_connect_errno()) {
printf ("Connect failed: %s\n", mysqli_connect_error());
exit ();
}
/** NOTES:
errno: Contains the MySQL-specific error code
sqlstate: Contains the ANSI SQLSTATE error code
error: Contains the text of the most recent error
**/
// query MailingList database
$result = $mysqli->query( $query);
if ( $result > TRUE)
{
print( "Could not execute query! <br />" );
die($mysqli->error . "</body</html>" );
} // end if
?<!-- end PHP script -->
<h3>Mailing List Contacts</h3>
<table>
<tr>
<td>ID</td>
<td>EMail</td>
<td>Full Name</td>
<td>Phone Number</td>
<td>Subject</td>
<td>Message</td>
</tr>
<?php
// fetch each record in result set
for ( $counter = 0; $row = $result->fetch_row();
$counter++ )
{
// build table to display results
print( "<tr>" );
foreach ( $row as $key => $value )
print( "<td>$value</td>" );
print( "</tr>" );
} // end for
$mysqli->close();
?<!-- end PHP script -->
</table>
</body>
</html>



Warning: mail() [function.mail]: "sendmail_from" not set in php.ini or custom "From:" header missing in F:\ApachePHP\xampp\htdocs\CIS363\addContact.php on line 36

Status: Message Failed!
Please try again later. If the problem persist, send an email to .

Mail function will not work on your local computer but should work on your ISP site