[go: up one dir, main page]

0% found this document useful (0 votes)
62 views7 pages

Build a Database-Driven Website

1. The document provides instructions for developing a database-driven web site using MySQL, Apache web server, and PHP. It lists the basic software and skills needed, including SQL, HTML, and basic PHP programming. 2. It then gives a quick primer on using HTML to create basic webpages and forms, PHP to get user input and store it in session variables, and PHP to connect to a MySQL database and perform queries. 3. The examples show how to use PHP to capture the customer name sent from a HTML form, connect to a database, query the orders table to find orders for that customer, and display the results.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
62 views7 pages

Build a Database-Driven Website

1. The document provides instructions for developing a database-driven web site using MySQL, Apache web server, and PHP. It lists the basic software and skills needed, including SQL, HTML, and basic PHP programming. 2. It then gives a quick primer on using HTML to create basic webpages and forms, PHP to get user input and store it in session variables, and PHP to connect to a MySQL database and perform queries. 3. The examples show how to use PHP to capture the customer name sent from a HTML form, connect to a database, query the orders table to find orders for that customer, and display the results.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd

Develop a Database-driven Web Site

Software Needed Basic Skills Needed


DBMS (MySQL) SQL
Web Server (Apache) HTML
[Link]
ml/[Link]
Programming/Scripting PHP (basic programming skills)
Language (PHP) [Link]
HP/php_syntax.asp

A Quick Primer
Saeed Akhlaghpour
(Based on slides by Prof. Animesh)
HTML
• Basic webpage and forms: [Link]

PHP getting information from user, keeping track of the session, and displaying dynamic webpages
• PHP FORMS: [Link]
– PHP $_GET: x
• PHP Session variable (to store info about user): [Link]

PHP Database functionality


• MYSQL database connect using PHP: [Link]
• MYSQL data retrieval using PHP: [Link]
HTML (Simple static webpage)
<HTML>
<HEAD>
te p ad.
<TITLE>Your Title Here</TITLE>
a s no
</HEAD> r s uch m l”
i to h t
<BODY>
a ny ed p u blic
<CENTER><IMG SRC=“[Link]" > </CENTER> file in
htm l”
v e r ’s “
<HR> te this Index. ebser
Crea e it as “ r your w
e
<H1>This is a Header</H1> Nam it und
p
<H2>This is a Medium Header</H2> Kee tory
c
dire
<P> This is a new paragraph!
<P> <B>This is a new paragraph! And used tag to display text IN BOLD </B>

<br><br>

Click here to visit <a href="[Link] my favorite search engine</a>


<br><br>
Click here to visit <a href="/[Link]"> html form example page -- version 1 -- </a>
</BODY>
</HTML>
Obtaining input from user using a HTML
<html>
<body>
l. html”
r mhtm
o
<h1>INSY-437 Web Application</h1> e it as “f
Na m
<p>Beta 1.0</p>
<br>
<br>

<form action= "[Link]" method= "get">


Customer Name: <input type="text" name= "custname" />
r th ey
<input type="submit" /> o g e , afte
ken t p pa
</form> ll b e ta
r d e r. ph
x t p age
s e r wi m e rO n . th e ne ”.
</body> U u s to b u tto b y a m e
owC submit accesse ., “custn d
</html> sh
ic k on a n be m e i.e
c l lue c sn a
v a a b le
The ng vari
si
by u
Capturing user input sent by previous page
and displaying it (USING PHP)
[Link]“
<html> rOrde
sto me
<body> Cu
“show ion.
e it as extens <? php
Nam CE the file i t h –
< h1>INSY-437 Web Application </h1> I
NOT IS A PH
P
ta rts w
<p>Beta 1.0</p> H I S O D Es th ;
T C ? > i
PHP with -- e n ds w
End m e nt
st ate
h PHP
Eac

Orders for Customer: <?php echo $_GET["custname"]; ?><br />

In PHP, Dot (.) is used to concatenate/combine text


</body> Be careful with the quotes: " and “ are different
</html> Use " (using simple editor like notepad)
Capturing user input sent by previous page
and displaying it (USING PHP)
r. php“
<html> r Orde
e
ustom
<body> howC
y “s
o d if
M
< h1>INSY-437 Web Application </h1>
<p>Beta 1.0</p>

Orders for Customer: <?php echo $_GET["custname"]; ?><br />

WE NEED TO WRITE SOMETHING TO QUERY THE DATABASE AND FIND THE


ORDERS

</body>
</html>
PHP code to connect to database and execute queries
<?php
/* USE YOUR OWN mysql_host, mysql_database, mysql_user, and mysql_password (see Step 5 of the tutorial) */
$conn = mysqli_connect( "[Link]", "a6589104_saeed", "password", "a6589104_saeeddb" );
if( $conn ) echo "It Works!!<br>";
else echo "Mysql doesn't work!<br>";

echo "Orders for Customer: " . $_GET["custname"] ."<br>";


$sql="SELECT CustomerName, OrderID, OrderDate FROM Order_T INNER JOIN Customer_T ON
Order_T.CustomerID=Customer_T.CustomerID WHERE CustomerName LIKE '".$_GET["custname"]."';";
$res=mysqli_query($conn, $sql);
echo "<br> Objective of this page:<b> Display Orders for Customer: " . $_GET["custname"] ."</b><br><br>";
. php“
echo "the query was: ".$sql."<br><br>Result <br><br>"; rder
e rO
to m
if ($res) Cus
“s how
{ while ($newArray=mysqli_fetch_array($res,MYSQLI_ASSOC))
his to
d t
{
Ad
echo "Customer Name: ". $newArray['CustomerName'] ."<br>";
echo "Order ID: ". $newArray['OrderID'] ."<br>";
n array
as a
echo "Order Date: ". $newArray['OrderDate'] ."<br>";
echo "---<br>";
lt ta ble
es u
}
th e r
}
ray gets
else tch ar
Fe
{ echo "query failed";
}
mysqli_close($conn);
?>

You might also like