WebDevelopment Lec4
WebDevelopment Lec4
Development
lecture 4
PHP Form Handling
Client: makes a request
requests an Internet
Client resource by
(browser) specifying a URL and
providing input via HTTP
Web encoded strings
browser
os
Internet
Network Core
Server: responds
• Webserver supports HTTP.
Server
Web
server My codes
PHP
HTTP HTML MySQL
interpreter
Client
Operating System
Web
TCP/IP
browser
Internet
What’s happening?
Client (browser) Web server
Find hello.php
Parse the file
Run php parts through PHP interpreter
Deliver resulting document to port 80
HTTP/1.1 200 OK
(document body)
Display resulting
document on the
screen
⦁ HTML5 provides forms for collecting
information from users.
⦁ Figure 2.14 is a simple form that sends data
to the web server for processing.
31
PHP Form Handling with POST
32
PHP Form Handling with GET
33
Using “name” attribute to get values of controls
34
PHP Form Validation
• Check mandatory fields:
35
Php + Html in the same file
36
PHP with MySQL
37
Why MySQL
• The most popular open source database
available is MySQL .
• It is one of the most widely used database
with PHP.
38
Design DB schema
• Analyze the raw data.
• Determine tables.
• Assign the columns (fields) of each table.
• Find relations between tables and each other
and their fields.
• Sketch out the full schema of your DB.
39
Search NCBI for Data
• Genes Database:
https://www.ncbi.nlm.nih.gov/gene/?term=Ar
abidopsis+thaliana
• Select Gene from results: PHYA
(https://www.ncbi.nlm.nih.gov/gene/837483)
• Try to find the valuable information and
description that can be columns in the Gene
table in my DB.
40
Gene’s details
41
Gene’s details
42
Fasta gene sequence
43
Php MyAdmin – Log in
44
Php MyAdmin – Create DB
45
Php MyAdmin – Create table
46
Insert -
Browse
table rows
47
Connect to MySQL Server using PHP
• PHP 5 and later can work with a MySQL
database using either:
• MySQLi extension (the "i" stands for
improved): only works with MySQL databases.
• PDO (PHP Data Objects): works on 12 different
database systems.
48
How to Connect to MySQL Using PHP
49
MySQLi Object-Oriented
• <?php
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "bioserverdb";
// Create connection
$conn = new mysqli($servername, $username, $password,
$dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
else { echo "Connected successfully"; }
// Close connection
$conn->close();
?> 50
Select Data With MySQLi
$sql = "SELECT * FROM gene";
$result = $conn->query($sql);
if ($result->num_rows > 0)
{
// output data of each row
while($row = $result-> fetch_assoc())
{
echo “Id: [" . $row[“GID"]. "] - Name: [" .
$row[“GName"]. "] – Fasta Sequence : [" .
$row["FastaSeq"]. "]<br>";
}
}
51
Results
52
Insert Data With MySQLi
$sql = "INSERT INTO gene (GID, GName, FastaSeq)
VALUES ('4', 'NC_003076.8', 'AAGGAAAAAAAAAAATAGAA
AGAGAAAACG') ";
54
55