Assign 6
Assign 6
Assignments no: 06
TITLE
Add dynamic web application essence using PHP, HTML and MySQL.
OBJECTIVES
To understand the principles and methodologies of PHP web based applications development
process,
PROBLEM STATEMENT
Design and develop dynamic web application using PHP and MySQL as a back-end for employee
data with insert, delete, view and update operations.
OUTCOMES
Page 40
Web Technology Lab Manual
THEORY-CONCEPT
1. PHP:
The PHP Hypertext Preprocessor (PHP) began as a little open source venture that advanced as an
ever increasing number of individuals discovered how valuable it was. Rasmus Lerdorf released
the principal form of PHP route in 1994. PHP is a recursive acronym for "PHP: Hypertext
Preprocessor".
PHP is a server side scripting dialect that is installed in HTML. It is utilized to oversee dynamic
substance, databases, session following, even form whole internet business locales. It is
incorporated with various prevalent databases, including MySQL, PostgreSQL, Oracle, Sybase,
Informix, and Microsoft SQL Server.
PHP is pleasingly zippy in its execution, particularly when gathered as an Apache module on the
Unix side. The MySQL server, once began, executes even extremely complex questions with
colossal outcome sets in record-setting time.
PHP bolsters a substantial number of real conventions, for example, POP3, IMAP, and LDAP.
PHP4 included help for Java and conveyed question designs (COM and CORBA), making n-
level improvement a plausibility out of the blue. PHP is excusing: PHP dialect tries to be as
pardoning as would be prudent. PHP Syntax is C-Like.
PHP performs framework capacities, i.e. from documents on a framework it can make, open,
read, compose, and close them. PHP can deal with frames, i.e. accumulate information from
records, spare information to a document; through email you can send information, return
information to the client.
You include, erase, adjust components inside your database through PHP. Access treats factors
and set treats. Utilizing PHP, you can confine clients to get to a few pages of your site. It can
encode information.
Page 41
Web Technology Lab Manual
Example:
To get a feel for PHP, first start with simple PHP scripts. Since "Hello, World!" is an essential
example, first we will create a friendly little "Hello, World!" script.
As mentioned earlier, PHP is embedded in HTML. That means that in amongst your normal
HTML (or XHTML if you're cutting-edge) you'll have PHP statements like this –
<html>
<head>
</head>
<body>
</body>
</html>
To create and run PHP Web pages three fundamental parts should be introduced on your PC
framework.
Web Server − PHP will work with for all intents and purposes all Web Server programming,
including Microsoft's Internet Information Server (IIS) however then regularly utilized is
unreservedly accessible Apache Server. Download Apache for nothing here −
https://httpd.apache.org/download.cgi
Database − PHP will work with for all intents and purposes all database programming,
including Oracle and Sybase yet most regularly utilized is uninhibitedly accessible MySQL
database. Download MySQL for nothing here − https://www.mysql.com/downloads/
Page 42
Web Technology Lab Manual
PHP Parser − keeping in mind the end goal to process PHP content directions a parser must be
introduced to create HTML yield that can be sent to the Web Browser. This instructional
exercise will manage you how to introduce PHP parser on your PC.
2. MySQL:
MySQL is the most famous Open Source Relational SQL Database Management System.
MySQL is outstanding amongst other RDBMS being utilized for creating different online
programming applications. MySQL is created, advertised and upheld by MySQL AB, which is
a Swedish organization. This instructional exercise will give you a fast begin to MySQL and
make you OK with MySQL programming.
What is a Database?
A database is a different application that stores a gathering of information. Every database has
at least one unmistakable APIs for making, getting to, overseeing, seeking and recreating the
information it holds.
Different sorts of information stores can likewise be utilized, for example, records on the
document framework or vast hash tables in memory yet information getting and composing
would not be so quick and simple with those kind of frameworks.
These days, we utilize social database administration frameworks (RDBMS) to store and
oversee tremendous volume of information. This is called social database since every one of the
information is put away into various tables and relations are set up utilizing essential keys or
different keys known as Foreign Keys.
RDBMS Terminology
Before we continue to clarify the MySQL database framework, let us modify a couple of
definitions identified with the database.
Page 43
Web Technology Lab Manual
MySQL Database
MySQL is a quick, simple to-utilize RDBMS being utilized for some little and huge
organizations. MySQL is produced, showcased and upheld by MySQL AB, which is a Swedish
organization. MySQL is winding up so famous as a result of numerous great reasons:
MySQL is discharged under an open-source permit. So you don't have anything to pay to
utilize it.
MySQL is a capable program in its own particular right. It handles a huge subset of the
usefulness of the most costly and intense database bundles.
MySQL utilizes a standard type of the outstanding SQL information dialect.
MySQL takes a shot at many working frameworks and with numerous dialects including
PHP, PERL, C, C++, JAVA, and so forth.
MySQL works rapidly and functions admirably even with extensive informational
indexes.
MySQL is amicable to PHP, the most refreshing dialect for web advancement.
MySQL underpins huge databases, up to 50 million lines or more in a table. The default
document measure restrain for a table is 4GB, yet you can expand this (if your working
framework can deal with it) to a hypothetical utmost of 8 million terabytes (TB).
Page 44
Web Technology Lab Manual
MySQL is adaptable. The open-source GPL permit enables developers to alter the
MySQL programming to fit their own particular surroundings.
TECHNOLOGY/TOOL
1. Technology is to be used is PHP (PHP Hypertext Preprocessor) and tool XAMPP server is to
be used to execute PHP web application.
2. XAMPP server embeds the PHP, MySQL and phpmyadmin, these three tools must be
required to run php web application.
DESIGN/EXECUTION STEPS
For the design purpose html and CSS is to be used. For this design part contains the GUI of web
applications, how its looks like? When users going to use the web application.
Steps to install XAMPP and configure the PHP, MYSQL server.
1. Download the XAMPP using following link (download latest version as per your Operating
system Windows/ Linux). Here we are using Linux Ubuntu Systems. Copy and paste downloaded
XAMPP into home location. https://www.apachefriends.org/download.html
3. After ab
4. ove command following installation window will appear.
Page 45
Web Technology Lab Manual
after successful completion of installation. It will ask to run XAMPP and here say to run. After run
the MySQL and Apache web server should be in running state. See below image.
As per above image you are ready with Apache Web Server and MySQL Database.
Page 46
Web Technology Lab Manual
after you become the root just type the following command to enter the root directory
cd /
“opt” is the directory in which XAMPP is installed by default.
6. As you have successfully installed and started XAMPP now just navigate to htdocs by typing the
following command into terminal:
Note: to edit or create any file in htdocs you need to be root : sudo -i
cd /
Page 47
Web Technology Lab Manual
8. To navigate to htdocs
cd opt/lampp/htdocs
gedit hello.php
<?php
echo(“Hello, Welcome to First PHP Application”);
?>
Here you can create the database and table inside database as per your need.Here we created “test”
database with “users” table contain four columns.
Page 48
Web Technology Lab Manual
CONCLUSION/ANALYSIS
In this assignment, we have studied how to design and develop small web application using PHP
script, XAMPP server with apache server and MySQL as backend.
Here we have created “emp” directory in htdocs directory contain following files
1. index.php
2. add.html
3. add.php
3. edit.php
4.delete.php
5. config.php
6. database.sql(optional)
1. index.php
<?php
//including the database connection file
include_once("config.php");
//fetching data in descending order (lastest entry first)
//$result = mysql_query("SELECT * FROM users ORDER BY id DESC"); // mysql_query is
deprecated
$result = mysqli_query($mysqli, "SELECT * FROM users ORDER BY id DESC"); // using
mysqli_query instead
Page 49
Web Technology Lab Manual
?>
<html>
<head>
<title>Homepage</title>
</head>
<body>
<a href="add.html">Add New Data</a><br/><br/>
<tr bgcolor='#CCCCCC'>
<td>Name</td>
<td>Age</td>
<td>Email</td>
<td>Update</td>
</tr>
<?php
//while($res = mysql_fetch_array($result)) { // mysql_fetch_array is deprecated, we need to
use mysqli_fetch_array
while($res = mysqli_fetch_array($result)) {
echo "<tr>";
echo "<td>".$res['name']."</td>";
echo "<td>".$res['age']."</td>";
echo "<td>".$res['email']."</td>";
echo "<td><a href=\"edit.php?id=$res[id]\">Edit</a> | <a
href=\"delete.php?id=$res[id]\" onClick=\"return confirm('Are you sure you want to
delete?')\">Delete</a></td>";
}
?>
</table>
</body>
Page 50
Web Technology Lab Manual
</html>
2. add.html
<html>
<head>
<title>Employee Data</title>
</head>
<body>
<a href="index.php">Home</a>
<br/><br/>
<tr>
<td>Name</td>
</tr>
<tr>
<td>Age</td>
</tr>
<tr>
<td>Email</td>
Page 51
Web Technology Lab Manual
</tr>
<tr>
<td></td>
</tr>
</table>
</form>
</body>
</html>
3. add.php
<html>
<head>
<title>Add Data</title>
</head>
<body>
<?php
include_once("config.php");
if(isset($_POST['Submit'])) {
Page 52
Web Technology Lab Manual
if(empty($name)) {
if(empty($age)) {
if(empty($email)) {
} else {
?>
</body>
</html>
4. edit.php
<?php
include_once("config.php");
if(isset($_POST['update']))
if(empty($name)) {
Page 54
Web Technology Lab Manual
if(empty($age)) {
if(empty($email)) {
} else {
header("Location: index.php");
?>
<?php
$id = $_GET['id'];
while($res = mysqli_fetch_array($result)) {
Page 55
Web Technology Lab Manual
$name = $res['name'];
$age = $res['age'];
$email = $res['email'];
?>
<html>
<head>
<title>Edit Data</title>
</head>
<body>
<a href="index.php">Home</a>
<br/><br/>
<table border="0">
<tr>
<td>Name</td>
</tr>
<tr>
<td>Age</td>
</tr>
Page 56
Web Technology Lab Manual
<tr>
<td>Email</td>
</tr>
<tr>
</tr>
</table>
</form>
</body>
</html>
5. delete.php
<?php
include("config.php");
$id = $_GET['id'];
header("Location:index.php");
?>
6. config.php
<?php
$database = 'localhost';
Page 57
Web Technology Lab Manual
$dbName = 'test';
$dbUser = 'root';
$dbPass = '';
?>
7. database.sql
a. create database emp;
b. use emp;
);
OUTPUT
1. First Window
Page 58
Web Technology Lab Manual
2. Second Window click on “Add New Data” see top left corner link
3. click “add” to add data in database and it will display below window
Page 59
Web Technology Lab Manual
4. Click on “View Result ” below image will be displayed with all details in database.
5. for delete and edit, use Update link from the right side of above web page.
ORAL QUESTIONS
10. What is JOIN in MySQL? What are the different types of join?
Page 60