0% found this document useful (0 votes)
19 views33 pages

Lec 7

Uploaded by

ulain7049
Copyright
© © All Rights Reserved
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)
19 views33 pages

Lec 7

Uploaded by

ulain7049
Copyright
© © All Rights Reserved
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
You are on page 1/ 33

Web Engineering

Lec 7

1
Semester Projects
Assignment No#4
1. Introduction
2. Problem Statement
3. Problem Solution for proposed system
4. Related system analysis/Literature review
5. Functional and non-functional requirements
6. Advantages of system
7. Scope
8. Module
9. System Limitations
10. Methodology
11. Tools and technologies
12. Data Gathering Approach
13. Mockups
14. Conclusion
15. References
2
GET and POST Methods

• Both GET and POST method is used to transfer data


from client to server in HTTP protocol but Main
difference between POST and GET method is that
• GET carries request parameter appended in URL string
• POST carries request parameter in message body
which makes it more secure way of transferring data
from client to
GET Method
GET Method
POST Method
POST Method
PHP
• What is PHP:
• PHP stands for : Hypertext Preprocessor”
• PHP is an open soruce server side scripting
language
• PHP is a partially case sensitive.
• PHP files have extension ".php"

8
PHP
• Why we use PHP?
We use PHP to create dynamic web pages/sites
• PHP runs on various platforms (Windows, Linux,
Unix, Mac OS X, etc.)
• PHP is compatible with almost all servers used
today (Apache, IIS, etc.)
• PHP supports a wide range of databases

9
PHP
• What do i need to run PHP pages
– Install a web server on your own PC and then install PHP
& MYSQL
– WAMP: Window, Apache, MYSQL, PHP
– XAMPP: All OS, Apache, MYSQL, PHP, Perl
Note: Install the web server start as services & then
type localhost in your browser to check whether it
is running or not
– LAMP: used for Linux Machines users

10
Editor
• Sublime Text Editor
• Notepad ++
• Notepad

11
PHP Syntax
Recommended
• PHP Tags: tags

1 2 3
Standard Tags Short Tags (Not supported Script Tags
<? Php by all web servers) <script language=”php<“
...code <? ...Code
?> .....Code </script>
?>

4
ASP Tags
<%
...code
%>

12
PHP
• MY First PHP Page: Open notepad and type the following code
<?php
Echo ”Welcome to PHP Class”;
?>
• Save it with php extension e.g. First.php
• How to run this?
– Open any web browser and type
– http://localhost/first.php
– The output will be
Welcome to PHP Class
https://www.youtube.com/watch?v=at19OmH2Bg4&list=PLu0W_9lII9aikXkRE0
WxDt1vozo3hnmtR 13
What is MySQL?
• MySQL is the most popular open-source
database system.
• The data in MySQL is stored in database
objects called tables.
• A table is a collections of related data
entries and it consists of columns and
rows.

14
Connection to MySQL Database
• Syntax
• In PHP, this is done with the mysqli_connect()
function.
• mysqli_connect(servername ,username,password,dbname );

15
Connection to MySQL Database
<?php
$link = mysqli_connect("localhost", "root", "", "dbname");
if($link === false){
die("ERROR: Could not connect. " . mysqli_connect_error());
}
echo "Connect Successfully" ;
mysqli_close($link);
?>

16
Create Database
• Syntax
CREATE DATABASE database_name
<?php
$link = mysqli_connect("localhost", "root", "","demo");
if($link === false){
die("ERROR: Could not connect. " . mysqli_connect_error());
}

$sql = "CREATE DATABASE demo";


if(mysqli_query($link, $sql)){
echo "Database created successfully";
} else{
echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
}
mysqli_close($link);
?>
17
Database Table
<?php
$link = mysqli_connect("localhost", "root", "","demo");
if($link === false){
die("ERROR: Could not connect. " . mysqli_connect_error());
}
$sql = "CREATE TABLE persons (
id INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
fname VARCHAR(30) NOT NULL,
lname VARCHAR(30) NOT NULL,
email VARCHAR(70) NOT NULL UNIQUE
)";
if(mysqli_query($link, $sql)){
echo "Table created successfully.";
} else{
echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
}
mysqli_close($link);
18
?>
PHP MySQL Insertion
• Syntax:
• 1st Method
– Syntax:
INSERT INTO table_Name VALUES (valu1, value2, ...)
• 2nd Method
– Syntax:
INSERT INTO table_Name(column1, column2,...)
VALUES(value1, value2,...)

19
PHP MySQL Insertion
<?php
$link = mysqli_connect("localhost", "root", "","demo");
if($link === false){
die("ERROR: Could not connect. " . mysqli_connect_error());
}
$sql = "INSERT INTO persons (id, fname, lname, email) VALUES (1, 'P1', 'P2',
[email protected]'), (2, 'P3', 'P4', ‘[email protected]')";
if(mysqli_query($link, $sql)){
echo "Records inserted successfully.";
} else{
echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
}
mysqli_close($link);
?>

20
PHP MySQL Selection
The SELECT statement is used to select data from one or more tables:
• Syntax:
SELECT column1_name, column2_name FROM table_name;

• Syntax:
or we can use the * character to select ALL columns from a table:
• SELECT * FROM table_name

• Syntax:
• SELECT column_name(s) FROM table_name WHERE column_name
operator value
21
<?php
PHP MySQL Selection echo "<tr>";
$link = mysqli_connect("localhost", "root", "", echo "<td>" . $row['id'] . "</td>";
"demo"); echo "<td>" . $row['fname'] . "</td>";
if($link === false) echo "<td>" . $row[‘lname'] . "</td>";
{ echo "<td>" . $row['email'] . "</td>";
die("ERROR: Could not connect. " . echo "</tr>"; }
mysqli_connect_error()); } echo "</table>";
$sql = "SELECT * FROM persons"; mysqli_free_result($result);
If }
($result = mysqli_query($link, $sql)) else
{ {
if(mysqli_num_rows($result) > 0) echo "No records found.";
{ }
echo "<table>"; }
echo "<tr>"; Else
echo "<th>id</th>"; {
echo "<th>fname</th>"; echo "ERROR: Could not able to execute $sql. " .
echo "<th>lname</th>"; mysqli_error($link);
echo "<th>email</th>"; }
echo "</tr>"; mysqli_close($link);
while($row = mysqli_fetch_array($result))
{ ?>

22
MYSQL Update Statement
• Used to update/modify records in a table
Syntax:
UPDATE Table_Name SET Column1=value1,
Column2=value2,...
where Some_Value=some_value;

23
Example
<?php
$link = mysqli_connect("localhost", "root", "","demo");
if($link === false){
die("ERROR: Could not connect. " . mysqli_connect_error());
}
$sql = "UPDATE persons SET email='[email protected]' WHERE id=1";
if(mysqli_query($link, $sql)){
echo "Records are updated successfully.";
} else {
echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
}
mysqli_close($link);
?>
24
MySQL Delete Statement
• Delete record from Database
Syntax:
DELETE FROM Table_name where some_Col=
some_value

25
Example
<?php
$link = mysqli_connect("localhost", "root", "","demo");
if($link === false){
die("ERROR: Could not connect. " . mysqli_connect_error());
}
$sql = "DELETE FROM persons WHERE id='1'";
if(mysqli_query($link, $sql)){
echo "Records were deleted successfully.";
} else{
echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
}
mysqli_close($link);
?>
26
PHP Session

• PHP - Sessions. An alternative way to make data


accessible across the various pages of an entire
website is to use a PHP Session.
• A session creates a file in a temporary directory on
the server where registered session variables and
their values are stored.
• PHP session technique is widely used in shopping
websites where we need to store and pass cart
information e.g. username, product code, product
name, product price etc from one page to another.
27
Why use PHP Sessions?
• State Management:
– Sessions enable the retention of user-specific data, such as login credentials or user preferences, across multiple
requests. This is crucial for maintaining the state of a user's interaction with a website.
• Security:
– Sessions provide a more secure way to store user data compared to using cookies. While cookies are stored on
the client side, sessions store data on the server side. This makes it harder for users to manipulate or tamper with
session data.
• User Identification:
– Sessions are commonly used for user identification and authentication. When a user logs in, a session variable is
often set to store the user's unique identifier, allowing the server to recognize the user across different pages.
• Customization:
– Sessions enable the customization of content based on user-specific preferences. For example, a user's theme
preference or language selection can be stored in a session variable and applied throughout their visit.
• Data Persistence:
– Unlike regular variables that lose their values after the script execution ends, session variables persist across
multiple pages until the user closes their browser or the session expires. This ensures that data remains
accessible throughout a user's interaction with the website.
• Shopping Carts and Forms:
– Sessions are commonly used to manage shopping carts in e-commerce websites. They help track items a user
has added to their cart across different pages. Sessions are also valuable for maintaining form data during multi-
step processes.
• Performance:
– Sessions can enhance website performance by reducing the need to repeatedly send and receive the same data
with each request. Once data is stored in a session, subsequent pages can access it without the need for constant
28
data transmission.
Starting a PHP Session

• To begin a new session, simply call the


session_start() function.
<?php

// Starting session
session_start();

?>

29
Storing and Accessing Session Data

<?php
// Starting session
session_start();
// Storing session data
$_SESSION["firstname"] = "Web";
$_SESSION["lastname"] = "Enginering";
// Accessing session data
echo $_SESSION["firstname"];
echo $_SESSION["lastname"];
?> 30
Accessing in different pages
Page1.php Page2.php
<?php <?php
// Starting session // Starting session
session_start(); session_start();
echo $_SESSION["firstname"]; echo $_SESSION["firstname"]
echo $_SESSION["lastname"]; echo $_SESSION["lastname"];

?> ?>

31
Destroying a Session
• To remove certain session data, simply unset the corresponding key
of the $_SESSION associative array
<?php

// Starting session
session_start();
// Removing session data
if(isset($_SESSION["lastname"]))
{
unset($_SESSION["lastname"]);
}
32
Destroying a Session
• To destroy a session completely, simply call the
session_destroy();

<?php

// Starting session
session_start();

// Destroying session
session_destroy();
33

You might also like