Download Guide for Building Web Application Using PHP and Mysql

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

URL redirection wikipedia , lookup

Transcript
Guide for Building Web Application Using PHP and Mysql
1. Download and install PHP, Web Server, 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. http://www.microsoft.com/web/webmatrix/
2. http://sourceforge.net/projects/wampserver/
PHP is compatible with various web servers like Apache and the Microsoft’s IIS as well. All the
PHP scripts are executed on the server (Apache, IIS etc) and it supports various databases like
MySQL, Oracle, Solid, Generic ODBC etc; however, it is mostly used with MySQL. A PHP file
has an extension of .phtml, .php 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. mysqi 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 icon ->PHP ->php.ini
Look at phpinfo( ) for get your server information
Example 1 of HTML and PHP Scripts for Search Product by Name and Type
In the following 3 files (posted on the class web page) : (To see source codes, 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
•
•
•
•
•
•
Search
APPS
MUSIC
View Transactions
Checkout
Logout
2. The first menu “Search” 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 button to submit.
Search
Enter Name :
Select category Type:
Search
MUSIC
Reset
3. Search button (in search_musicapp1.php) when clicked will
1) Process the input,
2) Connect to MySql database,
3) Query over database with the input to search,
4) Display the result on the next page.
APP
Sample PHP Codes with Search an employee in Company database in MySql
2. Build Search function in Company Website in root page to search an employee who is
working for the company as follow:
2-1. Company Webpage in root page “idex.html” has Search in menu. (You can list more
menu choice if you want)
2-2. Search page has Enter bar to take Last Name and two Buttons “Search” and “Reset”
2-3. On submit Search, it 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 form.
<?php
$con = mysqli_connect("localhost", "root", "") or die("Error connecting to database: ".mysqli_error());
mysqli_select_db($con, "company") or die(mysqli_error());
?>
<!DOCTYPE HTML>
<html>
<p><body>
<h3>Search Company Database</h3>
<p>Search by last name</p>
<form method="post" action="search.php?go" id="searchform">
<input type="text" name="name">
<input type="submit" name="submit" value="Search">
</form>
<form method="post" action="search.php" id="resetform">
<input type="submit" name="reset" value= "Reset">
</form>
</body>
</html>
</p>
<!DOCTYPE html>
<html>
<head>
<title>Search results</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="style.css"/>
</head>
<body>
<?php
if (isset($_POST['name'])){
$query = $_POST['name'];
echo
$sql = 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 </br>';
while ($row = mysqli_fetch_array($sql, MYSQL_ASSOC)) {
echo $row['FName']. " " .$row['LName']." " .$row['Sex'] . " " .$row['DNo'] ."</br>";
}
}
else{ // if there is no matching rows do following
echo "No results";
}
}
else{
echo 'Enter search conditions';
}
?>
</body>
</html>