You are on page 1of 47

Mahamaya Polytechnic Of

Information & Technology

Session - 2022-23
Web Development
Using ‘PHP’

Assignment
File

Submitted To Er. S.K Singh


Submitted By Chitvan Kumar

Enrollment No.- E20166535500013


Computer Science & Engg. {3rd Year (5th Sem.)}

Questions
1. What is PHP and write the syntax of PHP?
2. What is the difference between Echo and Print statement in PHP?
3. What is variable and type of variable in PHP with example?

1
Developed by Chitvan Kumar
4. What is Ajax and how its work?
5. What are the difference between while and do while loop?
6. What is Wordpress and explain different types of menus’.
7. Write the code to create connection using PHP with mysqli?
8. What are the difference between session and cookies?
9. Write the program in PHP to addition of any two numbers?
10. What is operator In PHP and explain any two operators with example?
11. Write the steps how to execute PHP program with XAMP server in CMD.
12. Write the steps how to execute PHP program using WAMP server.
13. Write the steps to set the permanent path to execute program in cmd.
14. Design the Student Registration page (Student Name, Mobile Number, Email id) using
HTML and CSS.
15. What is Control statement in PHP, explain with example?
16. Write the SQL Query to create database and Insert data into table using mysqli with PHP.
17. Explain synchronous and asynchronous in Ajax.
18. What is loop and explain any one loop with example?
19. Write the steps how to installation Wordpress.
20. What is plugin and how to use in Wordprss frame work?
21. How to use Categories in Wordpress frame work and explain all categories?
22. How to use Post in Wordpress?
23. How to use pages, blogs in Wordpress?
24. What is Media and how to use in Wordpress frame work?
25. To create table in database using Q.No-5 and perform all operations using mysqli with
PHP.

Answers

Ans 1: PHP

2
Developed by Chitvan Kumar
PHP is a server side scripting language that is used to develop Static websites or
Dynamic websites or Web applications. PHP stands for Hypertext Pre-processor, that earlier
stood for Personal Home Pages. PHP is an open source, server side general scripting language
that has now become a defact coding standard in the web development industry PHP runs on
different operating system such as Windows, Linux, Illnix and support different databases
MySQL, MS Access, Oracle.

 PHP is an acronym for "PHP: Hypertext Preprocessor"


 PHP is a widely-used, open source scripting language
 PHP scripts are executed on the server
 PHP is free to download and use
 PHP is faster than other scripting languages, for example, ASP and JSP.
 PHP is a server-side scripting language, which is used to manage the dynamic content of
the website.
 PHP can be embedded into HTML.
 PHP is an object-oriented language.
 PHP is an open-source scripting language.
 PHP is simple and easy to learn language.
 PHP scripts can only be interpreted on a server that has PHP installed.
 The client computers accessing the PHP scripts require a web browser only.
 A PHP file contains PHP tags and ends with the extension “.php”.

PHP is an amazing and popular language!


o It is powerful enough to be at the core of the biggest blogging system on the web
(WordPress).
o It is deep enough to run large social networks.
o It is also easy enough to be a beginner's first server side language!

Syntax Of PHP –

A PHP script can be placed anywhere in the document. A PHP script starts with <?php and ends
with ?>.

The default with file extension of PHP file is “.php”. A PHP file normally contain some HTML
tag and some PHP scripting code.

<?php
\\ PHP Code
?>

Ans 2: Echo and Print

We frequently use the echo statement to display the output. There are two basic ways to get the
output in PHP:

3
Developed by Chitvan Kumar
o echo

o print

echo and print are language constructs, and they never behave like a function. Therefore, there is
no requirement for parentheses. However, both the statements can be used with or without
parentheses. We can use these statements to output variables or strings.

Difference between echo and print

echo:

o echo is a statement, which is used to display the output.


o echo can be used with or without parentheses.
o echo does not return any value.
o We can pass multiple strings separated by comma (,) in echo.
o echo is faster than print statement.
o Example:
Code:-
<?php
$fname = "Chitvan";
$lname = "Kumar";
echo "My name is: ".$fname,$lname;
?>
Output:-

print:

o print is also a statement, used as an alternative to echo at many times to display the
output.
o print can be used with or without parentheses.
o print always returns an integer value, which is 1.
o Using print, we cannot pass multiple arguments.
o print is slower than echo statement.
o Example:

4
Developed by Chitvan Kumar
Code:-
<?php  
     $fname = "Chitvan";  
     $lname = "Kumar";  
     print "My name is: ".$fname,$lname;  
?> 
Output:-

Ans 3: Variables
Variables in a program are used to store some values or data that can be used later in a
program. The variables are also like containers that store character values, numeric values,
memory addresses, and strings. PHP has its own way of declaring and storing variables.  
There are a few rules, that need to be followed and facts that need to be kept in mind while
dealing with variables in PHP:  
 Any variables declared in PHP must begin with a dollar sign ($), followed by the
variable name.
 A variable can have long descriptive names (like $factorial, $even_nos) or short names
(like $n or $f or $x).
 A variable name can only contain alphanumeric characters and underscores (i.e., ‘a-z’,
‘A-Z’, ‘0-9, and ‘_’) in their name. Even it cannot start with a number.
 A constant is used as a variable for a simple value that cannot be changed. It is also
case-sensitive.
 Assignment of variables is done with the assignment operator, “equal to (=)”. The
variable names are on the left of equal and the expression or values are to the right of
the assignment operator ‘=’.
 One must keep in mind that variable names in PHP names must start with a letter or
underscore and no numbers.
 PHP is a loosely typed language, and we do not require to declare the data types of
variables, rather PHP assumes it automatically by analyzing the values. The same
happens while conversion. No variables are declared before they are used. It
automatically converts types from one type to another whenever required.
 PHP variables are case-sensitive, i.e., $sum and $SUM are treated differently.
 Example-
x= 50;
y=12-5;
z=”Hello World”;

 Types Of Variables –
Scope of a variable is defined as its extent in a program within which it can be
accessed, i.e. the scope of a variable is the portion of the program within which

5
Developed by Chitvan Kumar
it is visible or can be accessed. 
Depending on the scopes, PHP has three variable scopes:

1. Local variables:
The variables declared within a function are called local variables to that
function and have their scope only in that particular function. In simple words, it
cannot be accessed outside that function. 
Example-
<?php

    $num = 60;

    function local() {

        $num = 50;

        echo "Local Number = $num";

  }

    local();

    echo "Variable Number Outside Local Variable Is: $num\n";

?>

 OUTPUT-

2. Global variables :
The variables declared outside a function are called global variables.
These variables can be accessed directly outside a function. 
Example-
<?php
$num = 20;
function global_fun() {
        global $num;
        echo "Variable Number Inside Function Is: $num\n";
 }
  global_fun();
  echo "Variable Number Outside Function Is: $num\n";
?>

6
Developed by Chitvan Kumar
 OUTPUT-

Ans 4: AJAX
AJAX stands for Asynchronous JavaScript and XML. AJAX is a new technique
for creating better, faster, and more interactive web applications with the help of XML,
HTML, CSS, and Java Script.
 Ajax uses XHTML for content, CSS for presentation, along with Document
Object Model and JavaScript for dynamic content display.
 Conventional web applications transmit information to and from the sever using
synchronous requests. It means you fill out a form, hit submit, and get directed to
a new page with new information from the server.
 With AJAX, when you hit submit, JavaScript will make a request to the server,
interpret the results, and update the current screen. In the purest sense, the user
would never know that anything was even transmitted to the server.
 XML is commonly used as the format for receiving server data, although any
format, including plain text, can be used.
 AJAX is a web browser technology independent of web server software.
 A user can continue to use the application while the client program requests
information from the server in the background.
 Intuitive and natural user interaction. Clicking is not required, mouse movement is
a sufficient event trigger.
 Data-driven as opposed to page-driven.
 How Does AJAX Work?

AJAX communicates with the server using XMLHttpRequest object. Let's try to
understand the flow of ajax or how ajax works by the image displayed below.

7
Developed by Chitvan Kumar
1. User sends a request from the UI and a javascript call goes to XMLHttpRequest
object.
2. HTTP Request is sent to the server by XMLHttpRequest object.
3. Server interacts with the database using JSP, PHP, Servlet, ASP.net etc.
4. Data is retrieved.
5. Server sends XML data or JSON data to the XMLHttpRequest callback function.
6. HTML and CSS data is displayed on the browser.

______________________________________________________________________________

Ans 5: PHP do-while loop

PHP do-while loop can be used to traverse set of code like php while loop. The
PHP do-while loop is guaranteed to run at least once.

The PHP do-while loop is used to execute a set of code of the program several
times. If you have to execute the loop at least once and the number of iterations is not
even fixed, it is recommended to use the do-while loop.

It executes the code at least one time always because the condition is checked
after executing the code.

The do-while loop is very much similar to the while loop except the condition
check. The main difference between both loops is that while loop checks the condition at
the beginning, whereas do-while loop checks the condition at the end of the loop.

8
Developed by Chitvan Kumar
Flow Chart:

Example:
<?php    
$n=1;    
do{    
echo "$n<br/>";    
$n++;    
}while($n<=10);    
?>
Output:

PHP While Loop

PHP while loop can be used to traverse set of code like for loop. The while loop
executes a block of code repeatedly until the condition is FALSE. Once the condition
gets FALSE, it exits from the body of loop.

It should be used if the number of iterations is not known.

9
Developed by Chitvan Kumar
The while loop is also called an Entry control loop because the condition is
checked before entering the loop body. This means that first the condition is checked. If
the condition is true, the block of code will be executed.

Flow Chart:

Example:
<?php    
$n=1;    
while($n<=10){    
echo "$n<br/>";    
$n++;    
}  
?>

Ans 6: WordPress is a free, open-source website creation platform. On a more technical


level, WordPress is a content management system (CMS) written in PHP that uses a
MySQL database. In non-geek speak, WordPress is the easiest and most powerful
blogging and website builder in existence today.

10
Developed by Chitvan Kumar
It is considered as the easiest and most popular CMS tool due to its features. The
main feature of WordPress is its versatility and feasibility to use. There is no use of
coding and designing skills for creating a website on this. Even a non-technical person
can also create a website with the help of WordPress easily.

WordPress is an open-source community that implies thousands of people from


all over the world work on it. It is free software. You are free to download, install,
modify and use it. Although, there might be some cost involved during web hosting.

There are various customization Menu items available; some of them are as
follows:

 Navigation Label.

 Title Attribute.

 Link Target.

 Link Relationship.

 CSS Classes.

 Original

 Navigation Label

This field defines the title of the item on our custom menu. Our visitors will
see this when they visit our site or blog.

 Title Attribute

This field defines the alternative text ('Alt') for the menu item. This text will
be shown when the user's mouse is hovering over the menu item.

 Link Target

It allows users to choose the "Same window or tab" or "New window or


tab" from the dropdown menu.

 Link Relationship

It allows us to automatically create XFN features to demonstrate how we are


connected with the authors or owners of the site to whom we are linking.

 CSS Classes

11
Developed by Chitvan Kumar
It provides the optional CSS classes to the menu item.

 Original

It provides a link to the source of the menu item that helps us to see the page or post.

1. $host
Optional − The host name running the database server. If not specified,
then the default value will be localhost:3306.

2. $username
Optional − The username accessing the database. If not specified, then
the default will be the name of the user that owns the server process.

3. $passwd
Optional − The password of the user accessing the database. If not
specified, then the default will be an empty password.

4. $dbName
Optional − database name on which query is to be performed.

5. $port
Optional − the port number to attempt to connect to the MySQL server..

6. $socket
Optional − socket or named pipe that should be used.

______________________________________________________________________________

Ans 7: PHP provides mysqli contruct or mysqli_connect() function to open a database


connection. This function takes six parameters and returns a MySQL link identifier on
success or FALSE on failure.

 Syntax -

12
Developed by Chitvan Kumar
$mysqli = new mysqli($host, $username, $passwd, $dbName, $port, $socket);

Example-

<html>
    <head>
        <title>Connection To MySQL Server</title>
    </head>
    <body>
        <?php
            $dbhost = 'localhost';
            $dbuser = 'root';
            $dbpass = '';
            $mysqli = new mysqli($dbhost, $dbuser, $dbpass);
            printf('Connection successfully.<br>');
            $mysqli->close();
        ?>
    </body>
</html>

 OUTPUT-

Ans 8: Difference between Cookies and Sessions

COOKIES SESSIONS
Cookies are client-side files on a local Sessions are server-side files that contain
computer that hold user information. user data.

Cookies end on the lifetime set by the When the user quits the browser or logs
user. out of the programmed, the session is
over.
It can only store a certain amount of info. It can hold an indefinite quantity of data.

13
Developed by Chitvan Kumar
The browser’s cookies have a maximum We can keep as much data as we like
capacity of 4 KB. within a session, however there is a
maximum memory restriction of 128 MB
that a script may consume at one time.

Because cookies are kept on the local To begin the session, we must use the
computer, we don’t need to run a function session start() method.
to start them.

Cookies are not secured. Session are more secured compare than
cookies.

Cookies stored data in text file. Session save data in encrypted form.

Cookies stored on a limited data. Session stored a unlimited data.

In PHP, to get the data from Cookies , In PHP  , to set the data from Session,
$_COOKIES the global variable is used $_SESSION the global variable is used

We can set an expiration date to delete the In PHP, to destroy or remove the data
cookie’s data. It will automatically delete stored within a session, we can use the
the data at that specific time.  session_destroy() function, and to unset a
specific variable, we can use the unset()
function.
Cookies are client-side files that are stored Sessions are server-side files that store
on a local computer and contain user user information.
information.
Cookies expire after the user specified The session ends when the user closes the
lifetime. browser or logs out of the program.

It can only store a limited amount of data. It is able to store an unlimited amount of
information.
Cookies can only store up to a maximum There is a maximum memory restriction
of 4 KB of data in a browser. of 128 megabytes that a script may
consume at one time. However, we are
free to maintain as much data as we like
within a session.

It is not necessary for us to execute a Utilizing the session start()method is


function in order to get cookies going required before we can begin the session.
because they are stored on the local
computer.

14
Developed by Chitvan Kumar
Cookies are used to store information in a The data is saved in an encrypted format
text file. during sessions.

Cookies are stored on a limited amount of A session can store an unlimited amount
data. of data.

Ans 9: Student Registration Form


Code:
<html>
<head>
<title>Student Registration Form</title>
</head> 
<body>  
<form method="post">  
Enter First Number:  
<input type="number" name="number1" /><br><br>  
Enter Second Number:  
<input type="number" name="number2" /><br><br>  
<input  type="submit" name="submit" value="Add">  
</form>  
<?php  
    if(isset($_POST['submit']))  
  { 
        $number1 = $_POST['number1'];  
        $number2 = $_POST['number2'];  
        $sum =  $number1+$number2;    
echo "The sum of $number1 and $number2 is: ".$sum;  

?>  
</body>  
</html>

Output:

15
Developed by Chitvan Kumar
________________________________________________________________________

Ans 10: Operators


Operators are used to performing operations on some values. In other words, we
can describe operators as something that takes some values, performs some operation
on them, and gives a result. 

PHP Operators can be categorized in following forms:

o Arithmetic Operators
o Assignment Operators
o Bitwise Operators
o Comparison Operators
o Incrementing/Decrementing Operators
o Logical Operators
o Arithmetic Operators

The PHP arithmetic operators are used to perform common arithmetic operations
such as addition, subtraction, etc. with numeric values.

Operator Name Example Explanation

+ Addition $a + $b Sum of operands

- Subtraction $a - $b Difference of operands

* Multiplication $a * $b Product of operands

16
Developed by Chitvan Kumar
/ Division $a / $b Quotient of operands

% Modulus $a % $b Remainder of operands

** Exponentiatio $a ** $b $a raised to the power $b


n

Example:

<?php
    $x = 10;
    $y = 5;
    echo ($x+$y),"<br>";
    echo ($x-$y),"<br>";
    echo ($x*$y),"<br>";
    echo ($x/$y),"<br>";
    echo ($x%$y),"<br>";
?>

Output:

Assignment Operators

The assignment operators are used to assign value to different variables. The basic
assignment operator is "=".

Operato Name Example Explanation


r

= Assign $a = $b The value of right operand is assigned to


the left operand.

+= Add then Assign $a += $b Addition same as $a = $a + $b

-= Subtract then $a -= $b Subtraction same as $a = $a - $b

17
Developed by Chitvan Kumar
Assign

*= Multiply then $a *= $b Multiplication same as $a = $a * $b


Assign

/= Divide then $a /= $b Find quotient same as $a = $a / $b


Assign
(quotient)

%= Divide then $a %= $b Find remainder same as $a = $a % $b


Assign
(remainder)

Example:
<html>
    <head></head>
    <body>
        <?php
            $x = 10;
            echo $x;
        ?><br><?php
            $x += 100;
            echo $x;
        ?><br><?php
            $x -= 30;
            echo $x;
        ?><br><?php
            $x *= 6;
            echo $x;
        ?><br><?php
            $x /= 5;
            echo $x;
        ?><br><?php
            $x %= 4;
            echo $x;
        ?>
    </body>
</html>

Output:

18
Developed by Chitvan Kumar
Ans 11: PHP Installation for Windows Users
Follow the steps to install PHP on the Windows operating system.
 Step 1: First, we have to download PHP from it’s website. We have to
download the .zip file from the respective section depending upon on our system
architecture(x86 or x64).
 Step 2: Extract the .zip file to your preferred location. It is recommended to
choose the Boot Drive(C Drive) inside a folder named php (ie. C:\php).
 Step 3: Now we have to add the folder (C:\php) to the Environment Variable
Path so that it becomes accessible from the command line.
o To do so, we have to right click on My Computer or This PC icon, then
Choose Properties from the context menu.
o Then click the Advanced system settings link, and then click
Environment Variables.
o In the section System Variables, we have to find the PATH environment
variable and then select and Edit it.
o If the PATH environment variable does not exist, we have to click New.
In the Edit System Variable (or New System Variable) window, we have
to specify the value of the PATH environment variable (C:\php or the
location of our extracted php files).
o After that, we have to click OK and close all remaining windows by
clicking OK.

19
Developed by Chitvan Kumar
After installation of PHP, we are ready to run PHP code through command line.
You just follow the steps to run PHP program using command line.
 Open terminal or command line window.
 Goto the specified folder or directory where php files are present.
php file_name.php

Ans 12: WAMP Server Installation


After successfully download Wampserver install setup run as administrator. 
After Successfully Installed Wampserver open wampserver as like below :
All Programs — >> WampServer –>> Start WampServer

After start the Wampserver show the wampserver icon on taskbar near to clock
icon at right bottom of windows screen.
Below menu you can Start All Services and Stop All Services of wampserver.
There is a top most option “Localhost”, which shows the server configuration.

Now Click on “Localhost” you have below screen for server configuration.


Verson configuration PHP version and Apache Server Version configuration which  we
have already installed on our computer system.

20
Developed by Chitvan Kumar
Here, the “www directory” option define the path where we can save the PHP
file.
The default location path is “C:\wamp\www“.
We must save all PHP page at in “www” folder.

When we click on “www directory” option on above menu  it will locate directly


to www folder
In C drive, where we have to save all PHP file.
PHP Wampserver by default create a file index.php in www folder. Where we
run the index file on browser it look like : http://localhost/index.php 
Now, If you want to create new PHP file page, it must be save in www folder.
Suppose we create new file “demo.php”  in www folder. if we launch this file then we
must write like :  http://localhost/demo.php
If we want to create new website with new name then create new folder with your
website name in www folder like www -> MyWebsite. Now save all PHP pages
in MyWebsite folder. If we want to  launch this pages we should write like :
http://localhost/MyWebsite/index.php.
______________________________________________________________________________

Ans 13: PHP Installation

PHP Installation for Windows Users: Follow the steps to install PHP on the
Windows operating system.
 Step 1: First, we have to download PHP from it’s official website . We have to
download the .zip file from the respective section depending upon on our system
architecture(x86 or x64).

21
Developed by Chitvan Kumar
 Step 2: Extract the .zip file to your preferred location. It is recommended to choose
the Boot Drive(C Drive) inside a folder named php (ie. C:\php).
 Step 3: 
 Open control panel
 Go to System
 Choose the Properties tab
 Click Environment variables.
From this screen you can edit the environment variables of the system. If you only
wish to modify them on your user account, click New under your own variables box and
type in the following:
Variable name: Path
Variable value: %PATH%;C:\path\to\php
If you want the change to affect all users on the system, choose the Path variable
from the system variables box and click Edit.
Append the variable value with:
;C:\path\to\php
Note the ; character. It’s used to separate directories in the var, so be sure it’s
present.
Again, C:\path\to\php is where your php.exe is located.
Now, we should have the php executable available in command line.

____________________________________________________________________________

Ans 14: Student Registration Form


Code:
<html>
<head>
<title>Registration Form</title>
    </head>
    <body align="center" bgcolor="pink">
        <br><br>
        <form>

22
Developed by Chitvan Kumar
            <label> Student Name: </label>
            <input type="text" name="student" size="20" placeholder="Ex.
Chitvan"><br><br>
            <label> Mobile No.: </label>
<input type="number" name="student" size="20" placeholder="Ex. 1234567890"><br><br>
            <label> E-mail: </label>
<input type="email" name="student" size="20" placeholder="Ex. abc@gmail.com"><br><br>
            <button>Submit</button>
        </form>
    </body>
</html>

Output:

Ans 15: Control Statement


Control statements are conditional statements that execute a block of statements if
the condition is correct. The statement inside the conditional block will not execute until
the condition is satisfied
 if Statement:
The if statement in PHP is the most simplified control statement of the language.
The if condition works on a Boolean value which is evaluated based on a certain
condition and it is used to execute certain lines of code only if a condition is met or is
true.
Syntax:
if (condition) {
//code to be executed if condition is true;
}

23
Developed by Chitvan Kumar
Example:
<?php
$a = 16;
$b = 12;
If($a>$b)
echo “A is greater than 0”;
?>
Output:

 If…else Statement:
else…if, as its name suggests, is a combination of if and else. Like else, it
extends an if statement to execute a different statement in case the original if
expression evaluates to FALSE.
Syntax :

if (condition)
//code to be executed if condition is true;
else
//code to be executed if condition is false;

Example:
<?php
    $a = 10;
    $b = 20;
    if($a>$b)
        echo "a is greater than b";
    else
        echo "b is greater than a";
?>
 Output:

24
Developed by Chitvan Kumar
 if…elseif….else Statement
Use the if….elseif…else statement to select one of several blocks of code to be
executed.
Syntax :

if (condition)
//code to be executed if condition is true;
elseif (condition)
//code to be executed if condition is true;
else
//code to be executed if condition is false;

Example:
<?php
    $a = 10;
    $b = 20;
    if($a>$b)
        echo "a is greater than b";
    elseif($a<$b)
        echo "b is greater than a";
    else
        echo "a equals b";
?>
 Output:

 Switch Statement

25
Developed by Chitvan Kumar
The switch statement is similar to IF statements on the same expression. In many
occasions, you may want to compare the same variable (or expression) with many
different values, and execute a different piece of code depending on which value it
equals to.
Syntax :

switch ( ) {
case condition1
break;
case condition2
break;
}

Example:
<?php
    $i = 5;
    switch($i) {
        case 0:
            echo "i equals 0";
        case 1:
            echo "i equals 1";
        case 2:
            echo "i equals 2";
        default:
            echo "Not Valid";
  }
?>
 Output:

Ans 16: Database create in PHP


Code:
<?php
    $servername = "localhost";
    $username = "username";
    $password = '';

26
Developed by Chitvan Kumar
    $dbname = "myDB";
    // Create connection
    $conn = new mysqli($servername, $username, $password, $dbname);
    // Check connection
    if ($conn->connect_error) {
      die("Connection failed: " . $conn->connect_error);
  }
    $sql = "INSERT INTO student (firstname, lastname, email)
    VALUES ('Pragati', 'Sharma', 'pragatisharma30@example.com'),
            ('Chitvan','Kumar','chitvan@gmail.com'),
            ('Mukul','Kumar','mk@gmail.com'),
            ('Arshita','Kumari','arshita@gmail.com')";
    if ($conn->query($sql) === TRUE) {
      echo "New record created successfully";
    } else {
      echo "Error: " . $sql . "<br>" . $conn->error;
  }
    $conn->close();
?>
______________________________________________________________________________

Ans 17: Synchronous (Classic Web-Application Model)

A synchronous request blocks the client until operation completes i.e. browser is
unresponsive. In such case, javascript engine of the browser is blocked.
Synchronous AJAX is a process that makes a java script to halt or stop the
processing an application until a result is sent by a server. The browser is frozen, while
the request is processed. The response time is 99.99% quick and fast enough.

27
Developed by Chitvan Kumar
As we can see in the above image, full page is refreshed at request time and user
is blocked until request completes. In case of intrusion for a request or transfer of the file,
the browser freezes may be for two minutes until the time is out for the request.

Asynchronous (AJAX Web-Application Model)

An asynchronous request doesn’t block the client i.e. browser is responsive. At


that time, user can perform another operations also. In such case, javascript engine of the
browser is not blocked.

AJAX is not a proprietary technology, programming language or a packaged


product. Rather, it is a web browser technology and open standard that's independent
of web server software.

As we can see in the above image, full page is not refreshed at request time and
user gets response from the ajax engine.

28
Developed by Chitvan Kumar
Ans 18: Loop

Often when you write code, you want the same block of code to run over and over
again a certain number of times. So, instead of adding several almost equal code-lines in
a script, we can use loops.

Loops are used to execute the same block of code again and again, as long as a
certain condition is true.

In PHP, we have the following loop types:

 while - loops through a block of code as long as the specified condition is true
 do...while - loops through a block of code once, and then repeats the loop as
long as the specified condition is true
 for - loops through a block of code a specified number of times
 foreach - loops through a block of code for each element in an array
 The PHP foreach Loop
 The foreach loop works only on arrays, and is used to loop through each
key/value pair in an array.
 Syntax
foreach ($array as  $value) {
  code to be executed;
}
 For every loop iteration, the value of the current array element is assigned to
$value and the array pointer is moved by one, until it reaches the last array
element.
Code:
<?php  

$colors = array("red", "green", "blue", "yellow");


foreach ($colors as $value) {
  echo "$value <br>";
}
?>  

29
Developed by Chitvan Kumar
Output:

Ans 19: Download WordPress

Following some steps for dowmload WordPress are-


Step 1: Download WordPress

I. Download the WordPress package to your local computer


from https://wordpress.org/download/.
II. Unzip the downloaded file to a folder on your local computer.

Step 2: Upload WordPress to hosting account

There are three available options for uploading WordPress to your hosting
account. When you unzipped the file in Step 1, you were left with a folder
named wordpress, and the contents need to be uploaded to your hosting account's file
manager. You can accomplish this one of three ways:

 Upload via FTP - See How to Manage Files with Filezilla for more information.
 Upload via File Manager - See How to Upload Using the File Manager for
instructions.
 Upload via SSH - See How to Get and Use SSH Access for instructions.

Step 3: Create MySQL database and user

WordPress stores its information in a database. Therefore, a database will need to


be created.

I. Log in to cPanel.

30
Developed by Chitvan Kumar
II. Look for the Databases section, then click the MySQL Database
Wizard icon.

III. For Step 1: Create A Database, enter the database name, and click Next
Step.

IV. For Step 2: Create Database Users, enter the database user name and
password, and click Create User.

V. For Step 3: Add User to the Database, click the All Privileges checkbox and


click Next Step.

31
Developed by Chitvan Kumar
VI. For Step 4: Complete the task, make a note of the database name, username,
and password, as you will need them for Step 4⤵ below.

Step 4: Configure wp-config.php

The wp-config-sample.php file contains the database information and tells the


WordPress application from which database to pull data. This step must be completed to
ensure the correct database information is associated with the WordPress installation.

The wp-config-sample.php file can be found in File Manager in the folder where
WordPress is installed. The folder for your primary domain is public_html by default, so
the steps below show the process for that folder.

I. Log in to cPanel.
II. Navigate to the Files section, then click the File Manager icon.

III. From the left-hand navigation menu in File Manager, click public_html.


IV. Click on the Settings button found on the top right-hand corner of your
File Manager.

32
Developed by Chitvan Kumar
V. In the pop-up box, check the box for Show Hidden Files (dotfiles), then
click Save.

VI. In the right-hand panel of the File Manager, locate the wp-config-


sample.php file.

VII. Right-click on the file, then select Rename.


VIII. Change the name of the file to wp-config.php, then click the Rename
File button to save the change.
IX. Right-click again on the new wp-config.php file and select Edit.
X. A second pop-up box will appear. Click the Edit button.
XI. When the file opens, look for the following information:

/** The name of the database for WordPress */


define( 'DB_NAME', 'database_name_here' );
/** MySQL database username */
define( 'DB_USER', 'username_here' );
/** MySQL database password */
define( 'DB_PASSWORD', 'password_here'' );
/** MySQL hostname */
define( 'DB_HOST', 'localhost' );

o Replace database_name_here with the name of the database you


created (above in Step 3: Create MySQL Database and User ⤴).

33
Developed by Chitvan Kumar
o Replace username_here with the username of the database you
created.
o Replace password_here with the password of the database that
you created.
XII. Once done, click the Save Changes button on the top right, then Close to
exit and return to the File Manager.

Step 5: Run the installation

Open a new browser window and enter your domain to run the installation
script. Depending on where you installed the script, you will be automatically
redirected to either of the following URLs:

If you uploaded WordPress to the domain's root folder, you should be


redirected to:

https://example.com/wp-admin/install.php

If you uploaded WordPress to a subfolder of your domain's directory, then


the URL will be this format:

https://example.com/yoursubfolder/wp-admin/install.php

Step 6: Complete the installation

I. Once you access your correct WordPress URL in a browser, you will
see a WordPress setup page prompting you to select your preferred
language. Select your preferred language and click
the Continue button.

34
Developed by Chitvan Kumar
II. You should now see a welcome page that says, "Welcome to the
famous five-minute WordPress installation process!" Under
the Information needed section, you'll need to fill out the following
fields:

o Site Title - This can be changed at a later time.


o Username - This is the admin username for the site. We highly
recommend using something other than 'admin' since using it
can pose a security risk.
o Password- A strong password will be automatically generated
for you, but you can choose your own. The strength indicator
will let you know how secure your password is.
o Your Email- Login information will be sent to this email
address, so make sure it is an email address you have access to.
o Search Engine Visibility- If you want your website to show
up in search engine results, leave this unchecked. If you do not
want your site indexed, then you can check this box.
III. Click the Install WordPress button, and you should be taken to the
final screen, which says, "WordPress has been installed. Thank you,
and enjoy!". It will display the username you chose on the previous

35
Developed by Chitvan Kumar
page and a placeholder for your password. Click the Log In button to
log in to the WordPress Admin Dashboard to begin building your site!

______________________________________________________________________________

Ans 20: Plugins in WordPress


A plugin is a software add-on that is installed on a program, enhancing its
capabilities. For example, if you wanted to watch a video on a website, you may need a
plugin to do so. If the plugin is not installed, your browser will not understand how to
play the video.

The following list are examples of Internet browser plugins that can be installed
in a browser to extend its capabilities - Adobe Acrobat, Adobe Flash, Java, QuickTime,
RealPlayer, Shockwave, etc.

WordPress Plugin Development Frameworks and Resources for beginners of


WordPress plugin developers. We tried our best to introduce best frameworks
& resources as we can. Proper frameworks & resources can reduce your effort and save
your time. It also make sure you are applying best practices to your WordPress plugins.

 Herbert.

A structured and standardised approach to building plugins that’s the motto


of Herbert. The key features of Herbert framework is it allow you to use the power and
effectiveness of Laravel’s Eloquent ORM to handle your database queries. So now you
don’t need to stuck with the WordPress Database Object ($wpdb).

 WordPress Sanity Plugin Framework

The goal of this simple framework is to add some sanity and civility to
WordPress plugin development, a task which is currently messy and savage. So,
without further ado, I should like to present you with some sanity.

The key features of this framework :

 A template system that helps to separate your logic from your views.
 An easy way to include JS and CSS within the admin or front-end of your
plugin.

36
Developed by Chitvan Kumar
 AJAX in the admin made simple, with nonce integration out of the box.
 An object oriented approach to plugin development which makes
modifications easy.

Ans 21: Categories in WordPress


Add Categories

1. Go to your dashboard.
2. Click on  Posts → Categories.
3. Click Add New Category.
4. Give the new category a name and a description.
5. Click Add to save the new category.
By default, the category will be added as a “Top level Category.” To create
subcategories, toggle the switch, and choose the top-level category you want this
category associated with.

For example, a food blog might have categories for Cakes, Pies, and Ice Cream,
all under a top-level Dessert category.

Choose a Default Category

A default category is a category a post is assigned to by default when you


create a new post. All posts must be given a category. By default, the category
is Uncategorized.

37
Developed by Chitvan Kumar
1. Go to Posts →  Categories in your dashboard.
2. Click the ellipsis (three dots) to the right of the category you want to assign as the
default.
3. Select Set as default from the drop-down menu.

Changing the default Category.

While it is not possible to delete the “Uncategorized” Category, you can rename it
to whatever you want by clicking the Edit option in the drop-down menu next to the
category name.
Categorize your Posts

1. In your dashboard, click on Posts.


2. Click on the post you want to assign to a category.
3. Under Post Settings on the right, expand the Category option.
4. Click the checkbox next to the category you want the post to be assigned to
5. Click Update or Publish to apply the changes to that post.
If you don’t see the Settings sidebar, click the settings icon at the top of your page.

38
Developed by Chitvan Kumar
You can select multiple categories for a single post to show in. However,
you should not add more than five to 15 categories and tags to a post.

You can remove a post from a category by unchecking the box next to the
category name.

New Category from Within A Post

It is possible to quickly add a new category through the post’s Post Settings by
clicking on Add New Category.

You will be able to give the category a name and select a parent category.

If you want to add a description to the category, go back to your dashboard and
navigate to Posts → Categories to edit the new category.

39
Developed by Chitvan Kumar
Customize Category Pages

A category page is a page that displays all of the posts assigned to a


specific category. By default, there is an Archives page created for each category.
The archives page will have a URL, or site address, of something

like https://yourgroovysite.com/category/categoryname/.

If your site is using a theme that takes advantage of the Site Editor, you can
customize the Archives page’s template. Otherwise, it is styled by the theme you have
selected.

You can also create a custom category page using any WordPress block that
allows you to filter by category. These blocks include:

 Query Loop block


 Blog Posts block
 Post Carousel block

40
Developed by Chitvan Kumar
The default Archives page and any page that uses the blocks mentioned above
will automatically update with every new post you publish with that category.

Link to Category Pages


In Your Menu

You can link directly to the Category Archives page from your site’s
menu. When your visitors click on the link, they’ll navigate to the archives for the
category you linked to. For step-by-step instructions, check out the following
guide.

Add Categories to a Menu

If you’ve created a custom category page, you can link to it in your site’s menu
like any other page on your site.

Add Links to a Menu

If you have added a category to your site’s menu but do not see any posts on the
category page, or a message that says the content can’t be found, this means no posts
have been assigned to that category. Once you publish posts with the category they will
automatically show on the category page.

Using text, images, or buttons, you can link to your category pages (both archive
and custom pages) throughout your site. The following guide will walk you through
adding links to pages and posts on your site.

Add Links to your Site

Edit or Delete Categories

To edit or delete a category, go to Posts → Categories. Then, click the


ellipses (three dots) on the right of any category to find the following options:

 Edit: Change the name, parent category, and category description.

41
Developed by Chitvan Kumar
 Delete: Delete the category. This removes the category from your site but does
not delete any posts which had that category.
 Set as default: Assign as the default category.
Use Categories to Get Discovered

People can add specific tags and topics in their WordPress.com Reader for topics
they’re interested in following. Then, when your post uses a category they’ve added to
their topics, they’ll see your post in their Reader. Therefore, assigning tags and categories
to your post increases the chance that other WordPress.com users will see your content.

However, you don’t want irrelevant content on the topics listings or search, and
neither do we. That’s why we limit the number of tags and categories used on a public
topic listing. Five to 15 tags/categories is a good number to add to each of your
posts. The more categories you use, the less likely your post will be selected for
inclusion in the topics listings. 

Getting More Views and Traffic

Bulk Delete Categories

You can also edit your categories in bulk by going to Posts → Categories.

These instructions are referring to the WP Admin interface. To view this


interface, click the View tab in the upper right corner and select Classic view.

To bulk delete any categories, check all categories you want to be deleted,
and in the Bulk Actions drop-down above the list, select “Delete,” then click the
“Apply” button.

42
Developed by Chitvan Kumar
Ans 22: Creating a WordPress

1. Login to your WordPress Dashboard.


2. Click the Posts link in the navigation menu.
3. Click the Add New button on the Posts page.

4. Enter a title in the available field. This will display on the top of your Post.

5. Enter your page content in the available field. You can use the Editor to format
your text.

6. We can also click the Add Media button to add images, audio, etc.

43
Developed by Chitvan Kumar
7. Once you have entered your information in the Post, click the Publish button.
(You can also click Save Draft to save your work without publishing the Post)

8. We are finished when we see a Post published message.

Ans 23: Use Pages and Bolgs in WordPress


“Blog” is an abbreviated version of “weblog,” which is a term used to describe
websites that maintain an ongoing chronicle of information. A blog features diary-type
commentary and links to articles on other websites, usually presented as a list of entries
in reverse chronological order. Blogs range from the personal to the political, and can
focus on one narrow subject or a whole range of subjects.

1. Add a new page in WordPress

Log in to your WordPress Dashboard, and click on Pages > Add New. This
step is pretty self-explanatory. Since you already have an existing business website
and you want to add a blog, you’ll need a page for your blog to live. You don’t want
it encroaching on other pertinent page information.

2. Name the page

Let’s name it “Blog” for easy identification. Leave the text box blank because
you want the page to act as a feed for your posts — not a static read page.

3. Publish the page

In order for your Blog page to go live, you need to publish it. 

4. Navigate to the Settings section

When you’re in your Dashboard, you’ll see a column along the left with all
the different things you can do in WordPress. Go to Settings > Reading .

5. Designate a Posts page

44
Developed by Chitvan Kumar
Click on A static page, and then select Blog under the drop-down menu
for Posts page. This is important. This step determines where your blog feed
appears. 

6. Determine the amount of posts you want.


7. Write and publish your first post.

Ans 24: Media


WordPress media includes images, audio, videos, documents, spreadsheet, and
files that are used all over the website. We first have to upload media that takes the
server space to store the file and images and then we can insert anywhere at the website
to use it. To see the media library we have to go to Media >> Library.
The Media Library Screen gives us the ability to view, delete, and change the
media file name and info for uploaded media to the website. We can upload and delete
multiple media files at a time. The Media library can be visible in two available modes
lists and grid. We can use the filter option to filter the data between images, documents,
videos, spreadsheets, and more. You can find your desired media from the whole list by
searching with the name of the media file in the search inbox.
Ø  Upload New Media: 
To upload a new media file on the website, you’ll find an option from
the Media Library section called “Add New”. You have two ways to add a new
media after clicking Add New button, either simply drag and drop the file to the
Upload section (see image below), or click on Select File to select a file from
your local system.

 
Ø  Customize Media Library: 
At the top of the Media Library, you will find the bar that contains
options as View Mode, Filter by item, Filter by date, Bulk Select button, and a
Search inbox. 
 

45
Developed by Chitvan Kumar
Ans 25: Creating Table in Database
Code:
<?php
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "myDB";

$conn = new mysqli($servername, $username, $password, $dbname);


if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$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 DEFAULT CURRENT_TIMESTAMP ON UPDATE
CURRENT_TIMESTAMP
)";

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


echo "Table MyGuests created successfully";
} else {
echo "Error creating table: " . $conn->error;
}
$conn->close();
?>

46
Developed by Chitvan Kumar
47
Developed by Chitvan Kumar

You might also like