<<

Guide for Building Using PHP and Mysql

1. Download and install PHP, Web , and MySql from one of the following sites. You can look up the lecture notes on the class webpage for tutorials of HTML, PHP and more to create webpages as needed.

1. ://sourceforge.net/projects/wampserver/ 2. https://www.microsoft.com/web/webmatrix/

PHP is compatible with various web servers like Apache and the ’s IIS as well. All the PHP scripts are executed on the server (Apache, IIS etc) and it supports various like MySQL, Oracle, Solid, Generic ODBC etc; however, it is mostly used with MySQL. A PHP file has an extension of .phtml, . or .php3 and it may contain various HTML tags, texts and scripts. Although a .php file contains scripts but when it is returned to the browser, it is returned as a plain HTML file. You can view a PHP file in Notepad as a source as well (right click on php file to select Edit with NotePad ).

Note: Some MySql Commands in an old version are deprecated in the latest versions of WAMPServer, they will raise errors. mysq i are the new format for commands.

Note that there may be version mismatch problems. Not all versions of PHP's will run with Apache2.4.

For more info for this problem: http://forum.wampserver.com/read.php?2,119754,119754

Additional Guide to Set up:

Edit Wamp Server ->PHP ->php.ini

Look at phpinfo( ) for get your server information

Example Codes in ., search_musicapp.php, search_musicapp1.php on the Class Webpage that implement the following Music Search.

Example 1 of HTML and PHP Scripts for Search Music by Name and Type

In the following 3 files (posted on the class ) : To see source codes of php file, right click on the file, select Edit with Notepad or view as Source. Or you can open the folder as Web in VS. index.html search_musicapp.php search_musicapp1.php

1. Root Page in (index.html) shows menus in first page

• APPS • MUSIC • View Transactions • Checkout • Logout

2. In the menu “MUSIC” will display the next page: Search Page (in search_musicapp.php) that takes Name of product to search and Category Type of product as input and Search to submit.

Search

Enter Name :

Select category Type: MUSIC APP

Search Reset

3. Search button (in search_musicapp1.php ) when clicked will

1) Send the input to the Webserver,

2) Connect to MySql ,

3) Query over database with the input to search,

4) Display the result on the next page. The following Sample PHP Codes that implements a similar task with Search an employee with Name on the Company from Company database in MySql is given below:

Build Search function in Company Website in root page to search an employee who is working for the company as follow:

1. Company Webpage in root page “idex.html” has Search in menu. (You can list more menu choice if you want). When Search link in the menu is clicked, the next page (SerachPage.php) is displayed.

2. In the next Search Page (in SerachPage.php) has Text input box to take Last Name of Employee and two Input Buttons “Search” and “Reset”

3. On Submit the button Search, the server script (in Search.php) will be executed to display the serach result in the next page. Serach.php will connect to your database, search Employee table to find an employee with the Last Name. Then on next page, it will display the employee information as output: First, Last Name, Sex, Dno of the employee in Table .

Sample codes for this Lab:

1. Create Index.html that shows all the home page menu including SEARCH menu with a href = “SearchPage.php”

In index.html:

xml:lang= "en" lang ="en" > Company Home Page css" />

2. SerachPage.php will be executed to display the following input boxes.

In SerachPage.php, the script would look like this as below:

Search Company Database

Search by last name

3. search.php will be executed to display the result on the next webpage. In search.php: The server script would look like this as below.

Search results

if (isset($_POST['name'])){ $query = $_POST['name'];

$ = mysqli_query($con, "SELECT * FROM employee

WHERE (`LName` LIKE '%".$query."%')") or die(mysqli_error($con)); if (mysqli_num_rows($sql) > 0) {

// if one or more rows are returned do following echo 'Fname Lname Sex DNo
'; while ($row = mysqli_fetch_array($sql, MYSQL_ASSOC)) {

echo $row['FName']. " " .$row['LName']." " .$row['Sex'] . " " .$row['DNo'] ."
"; }

} else{ // if there is no matching rows do following echo "No results"; } } else{ echo 'Enter search conditions'; }

?>