Unit 5 (B)

Download as pdf or txt
Download as pdf or txt
You are on page 1of 31

Web Designing

Web application development


Outline
⚫ Wordpress – CMS introduction
⚫ Basic technology –HTML/CSS
introduction
⚫ Server side programming - PHP
⚫ Introduction to XAMPP
WORDPRESS
WordPress is an open source Content Management System
(CMS), which allows the users to build dynamic websites and blogs.
What is blog? a regularly updated website or web page, typically one run
by an individual or small group, that is written in an informal or
conversational style- with latest posts appearing first

Features
User management
Media Management
Theme System
Extended plugins
Multilingual
Accessories / Requirement
Database − MySQL 5.0 +
Web Server −
WAMP (Windows)
LAMP (Linux)
XAMP (Multi-platform)
MAMP (Macintosh)
Operating System − Cross-platform
Browser Support − IE (Internet Explorer 8+), Firefox, Google
chrome, Safari, Opera
PHP Compatibility − PHP 5.2+

Install wordpress

https://wordpress.org/download/
WordPress requires MySQL database. So create a new empty database
with user/password
Click on Run the install
Step (6) − Enter administrative information.
How to proceed
Create Login
Choose Language
Choose type of website
Choose Domain

Wordpress Dashboard
What is PHP?

PHP is one of the primary server-side programming languages for the web
and is what powers a lot of WordPress.
PHP allows you to do some important things:
❑Save content to a database
❑Read content from a database
❑Write loops and conditional statements
❑Pull in WordPress specific information
❑Pull in files like images, media
❑Can pull in files like images, media and other PHP, CSS and JS files

you’re usually just looking through already written PHP in order to customize
little bits and pieces
HTML and PHP
A PHP file is simply a file that ends with .php. Some PHP files contain only
PHP code and some contain a combination of PHP and HTML code.

Within all of the different types of PHP files, you will find what’s called a
PHP block. When you write PHP you need to write it inside of PHP
blocks otherwise it will display as plain text and not be processed as a
programming language by the server.
A PHP block starts with a “<?php” and ends with a “?>”. Blocks can span
many lines or sometimes appear inline along with other code.
Here is an example of a PHP block with a PHP comment inside of it.
<?php
// Example of a PHP Comment
?>

PHP statements end with a semicolon (;).


In PHP, NO keywords (e.g. if, else, while, echo, etc.), classes, functions,
and user-defined functions are case-sensitive.
However; all variable names are case-sensitive.
Variable Declaration
<?php
$txt = "Hello world!";
$x = 5;
$y = 10.5;
?>

Output Variable
<?php
echo "<h2>PHP is Fun!</h2>";
echo "Hello world!<br>";
echo "I'm about to learn PHP!<br>";
echo "This ", "string ", "was ", "made ", "with multiple
parameters.";
echo $x ;
?>
Data Type
PHP supports the following data types:
String
Integer
Float (floating point numbers - also called double)
Boolean
Array
Object
NULL
Resource
Constants and Functions
<?php
define("GREETING", "Welcome to W3Schools.com!");

function myTest() {
echo GREETING;
}

myTest();
?>
Control statements
<?php
$t = date("H");

if ($t < "20") {


echo "Have a good day!";
}

switch (n) {
case label1:
code to be executed if n=label1;
break;
}
while($x <= 5) {
echo "The number is: $x <br>";
$x++;
}
?>
Form
<!DOCTYPE HTML>
<html>
<body>

<form action="welcome.php" method="post">


Name: <input type="text" name="name"><br>
E-mail: <input type="text" name="email"><br>
<input type="submit">
</form>

</body>
</html>
Welcome.php

<html>
<body>

Welcome <?php echo $_POST["name"]; ?><br>


Your email address is: <?php echo $_POST["email"]; ?>

</body>
</html>
Get method

<html>
<body>

<form action="welcome_get.php" method="get">


Name: <input type="text" name="name"><br>
E-mail: <input type="text" name="email"><br>
<input type="submit">
</form>

</body>
</html>
Get method

<html>
<body>

Welcome <?php echo $_GET["name"]; ?><br>


Your email address is: <?php echo $_GET["email"]; ?>

</body>
</html>
MySQL
MySQL is the most popular database system used with PHP.
The data in a MySQL database are stored in tables. A table is a collection
of related data, and it consists of columns and rows.
What is MySQL?
MySQL is a database system used on the web
MySQL is a database system that runs on a server
MySQL is ideal for both small and large applications
MySQL is very fast, reliable, and easy to use
MySQL uses standard SQL
MySQL compiles on a number of platforms
MySQL is free to download and use
MySQL is developed, distributed, and supported by Oracle Corporation
MySQL is named after co-founder Monty Widenius's daughter: My
MySQL Connect
MySQLi extension (the "i" stands for improved) - only for MySQL
PDO (PHP Data Objects) - for all databases

<?php
$servername = "localhost";
$username = "username";
$password = "password";

// Create connection
$conn = mysqli_connect($servername, $username, $password);

// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
echo "Connected successfully";
?>
Create New MySQL Database
<?php
$servername = "localhost";
$username = "username";
$password = "password";

// Create connection
$conn = new mysqli($servername, $username, $password);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}

// Create database
$sql = "CREATE DATABASE myDB";
if ($conn->query($sql) === TRUE) {
echo "Database created successfully";
} else {
echo "Error creating database: " . $conn->error;
}
$conn->close();
?>
<?php
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "myDBPDO";

try {
$conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $passw
// set the PDO error mode to exception
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql = "INSERT INTO MyGuests (firstname, lastname, email)
VALUES ('John', 'Doe', '[email protected]')";
// use exec() because no results are returned
$conn->exec($sql);
echo "New record created successfully";
} catch(PDOException $e) {
echo $sql . "<br>" . $e->getMessage();
}

$conn = null;
?>
Create Table
$sql = "CREATE TABLE MyGuests (
id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
firstname VARCHAR(30) NOT NULL,
lastname VARCHAR(30) NOT NULL,
email VARCHAR(50),
reg_date TIMESTAMP
)";

if ($conn->query($sql) === TRUE)

if (mysqli_query($conn, $sql))
Insert Data
<?php
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "myDB";
// Create connection
$conn = mysqli_connect($servername, $username, $password,
$dbname);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
$sql = "INSERT INTO MyGuests (firstname, lastname, email)
VALUES ('John', 'Doe', '[email protected]')";
if (mysqli_query($conn, $sql)) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . mysqli_error($conn);
}

mysqli_close($conn);
?>
Select and Display Data
<?php

$sql = "SELECT id, firstname, lastname FROM MyGuests";


$result = mysqli_query($conn, $sql);

if (mysqli_num_rows($result) > 0) {
// output data of each row
while($row = mysqli_fetch_assoc($result)) {
echo "id: " . $row["id"]. " - Name: " . $row["firstname"]. " " .
$row["lastname"]. "<br>";
}
} else {
echo "0 results";
}

mysqli_close($conn);
?>
Delete Data
<?php

// sql to delete a record


$sql = "DELETE FROM MyGuests WHERE id=3";

if ($conn->query($sql) === TRUE) {


echo "Record deleted successfully";
} else {
echo "Error deleting record: " . $conn->error;
}

$conn->close();
?>
Files inclusion
The include() Function
The require() Function

<html> <body> <?php include("menu.php"); ?>


<?php require("xxmenu.php"); ?>
<p>This is an example to show how to include PHP file!</p> </body>
</html>

there is no difference in require() and include() except they handle error


conditions
Files Handling

<?php $filename = "tmp.txt";


$file = fopen( $filename, "r" );
if( $file == false ) { echo ( "Error in opening file" ); exit(); }
$filesize = filesize( $filename );
$filetext = fread( $file, $filesize );
fclose( $file );
echo ( "File size : $filesize bytes" );
echo ( "<pre>$filetext</pre>" );
?>
PHP functions

<?php /* Defining a PHP Function */

function writeMessage() {
echo "You are really a nice person, Have a nice time!"; }
/* Calling a PHP Function */

writeMessage();

<?php function addFunction($num1, $num2) {


$sum = $num1 + $num2;
echo "Sum of the two numbers is : $sum";
}

addFunction(10, 20); ?>

Pass by reference --- &$num1


Dynamic function call, default values
Questions
What is MySQL?
What are the technical features of MySQL?
Why MySQL is used?
What are Heap tables?
What is the default port for MySQL Server?
What are the advantages of MySQL when compared with Oracle?
Differentiate between FLOAT and DOUBLE?
Differentiate CHAR_LENGTH and LENGTH?
How to represent ENUMs and SETs internally? What is the usage of ENUM?
Define REGEXP?
Difference between CHAR and VARCHAR?
What storage engines are used in MySQL?
What are the drivers in MySQL?
What is the difference between primary key and candidate key?
How do you login to MySql using Unix shell?
What happens when the column is set to AUTO INCREMENT and if you
reach maximum value in the table?
What do you mean by % and _ in the LIKE statement?
What are the column comparisons operators?
How can we get the number of rows affected by query?
What is the difference between BLOB AND TEXT?
What is the difference between mysql_fetch_array and mysql_fetch_object?
What are the different tables present in MySQL?
What are the objects can be created using CREATE statement?
What are all the Common SQL Function?
Explain Access Control Lists.

You might also like