0% found this document useful (0 votes)
13 views83 pages

PHP Practicalbookljcca

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views83 pages

PHP Practicalbookljcca

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 83

Introduction to PHP

What is PHP?
▪ PHP stands for PHP: Hypertext Preprocessor
▪ PHP is a server-side scripting language
▪ PHP scripts are executed on the server
▪ PHP supports many databases (MySQL, Informix, Oracle, Sybase, Solid,
PostgreSQL, Generic ODBC, etc.)
▪ PHP is open source software
▪ PHP is free to download and use

What is XAMPP?
XAMPP is an open source cross platform web server, MySQL database engine, and
PHP and Perl package. It is compiled and maintained by apache. The acronym
XAMPP stands for;

• X – [cross platform operating systems] meaning it can run on any OS Mac OX


, Windows , Linux etc.
• A – Apache - this is the web server software.
• M – MySQL - Database.
• P – PHP
• P – Perl – scripting language

Why use XAMPP?


• In order to use PHP, you will need to install PHP, Apache and may be even
MySQL. It’s not easy to install Apache and configure it. If you install Apache
on its own, you will still have to set it up and integrate it with PHP and Perl
among other things. XAMPP deals with all the complexity in setting up and
integrating with PHP and Perl. Unlike Java that runs with the Java SDK only,
PHP requires a web server to work
• XAMPP provides an easy to use control panel to manage Apache, MySQL and
other programs such as Tomcat, filezilla etc. You don’t have to memorize
commands for starting apache, MySQL etc.
Basic Web server configuration
The following is a list of the basic directories that you are supposed to be aware of.

• htdocs; this is the web root directory. All of our PHP codes will be placed in
this directory.
• mysql – this directory contains all the information related to MySQL database
engine, by default it runs on port 3306.
• php – this directory contains PHP installation files. It contains an important
file named php.ini. This directory is used to configure how PHP behaves on
your server.

By default, the Apache web server runs on port 80. If port 80 is taken by another
web server, you can use a different port number.

What is the PHP IDE?

Netbeans IDE

Dreamweaver

PHP Eclipse

Notepad ++

Basic PHP Syntax


▪ A PHP script starts with <?php and ends with ?>
▪ The default file extension for PHP files is ".php"
▪ A PHP file normally contains HTML tags, and some PHP scripting code
▪ PHP statements are terminated by semicolon (;)
▪ In PHP, all user-defined functions, classes, and keywords (e.g. if, else, while,
echo, etc.) are not case-sensitive

Hello World example


<html>
<body>
<?php
// Use echo to print on console
echo ‚Hello World!‛;
?>
</body>
</html>

Go to htdocs folder which is present in the xampp installed folder. There create a folder of yours
“MyPHPProgram” and save this program with .php extension such as Hello.php.

To execute hello world program, type in the address bar as follows:


http://localhost:8080/MyPHPProgram/hello.php

Comments in PHP
▪ // Single line comment (C++ and Java-style comment)
▪ # Single line comment (Shell-style comments)
▪ /* Multiple line comment (C-style comments) */

PHP Data Types


A Data type is the classification of data into a category according to its attributes;

• Alphanumeric characters are classified as strings


• Whole numbers are classified integers
• Numbers with decimal points are classified as floating points.
• True or false values are classified as Boolean.

PHP is a loosely typed language; it does not have explicit defined data types. PHP
determines the data types by analyzing the attributes of data supplied. PHP
implicitly supports the following data types

PHP is a Loosely Typed Language


▪ In PHP, a variable does not need to be declared before adding a value to it
▪ PHP automatically converts the variable to the correct data type, depending
on its value
▪ In PHP, the variable is declared automatically when you use it
▪ PHP variables must begin with a “$” sign
▪ Variables are used for storing values, like text strings, numbers or arrays
▪ The correct way of declaring a variable in PHP: $var_name = value;
The rules followed when creating variables in PHP
• All variable names must start with the dollar sign e.g. $my_name
• Variable names are case sensitive; this means $my_name is different from
$MY_NAME
• All variables names must start with a letter follow other characters e.g. $my_name1.
$1my_name is not a legal variable name.
• Variable names must not contain any spaces, “$first name” is not a legal variable
name. You can instead use an underscore in place of the space e.g. $first_name.
You cannott use characters such as the dollar or minus sign to separate variable
names.

PHP Variables Example


<html>
<body>

<?php
$a = 25; // Numerical variable
$b = ‘Hello‛; // String variable
$c = 5.7; // Float variable
echo ‘Number is : ‛.$a.‚<br/>‛;
echo ‘String is : ‛.$b.‚<br/>‛;
echo ‘Float value : ‛.$c;
?>
</body>
<html>

OUTPUT of the above given Example is as follows:

Number is : 25
String is : Hello
Float value : 5.7

Global and locally-scoped variables


▪ Global variables can be used anywhere
▪ Local variables restricted to a function or class

Example for Global and locally-scoped variables


<html>
<body>
<?php
$x=24; // global scope
// Function definition
function myFunction() {
$y=59; // local scope
echo "Variable x is: $x <br>";
echo "Variable y is: $y";
}
myFunction();// Function call
echo "Variable x is: $x";
echo "<br>";
echo "Variable y is: $y";
?>
</body>
</html>

OUTPUT of the above given Example is as follows:


Variable x is:
Variable y is: 59
Test variables outside the function:
Variable x is: 24

Variable y is:

ECHO and PRINT statements in PHP


▪ ECHO - It can output one or more strings
▪ PRINT – It can only output one string, and returns always 1
▪ ECHO is faster compared to PRINT as echo does not return any value
▪ ECHO is not a function and, as such, it does not have a return value
▪ If you need to output data through a function, you can use PRINT() instead:

Example:
echo 50;
print (50);

PRINT Statement Example in PHP


<html>
<body>
<?php
// Use ‘print’ to print on console
print "Welcome Good Morning!<br>***********";
?>
</body>
</html>

OUTPUT of the above given Example is as follows: Welcome Good Morning!


String Functions in PHP
PHP string functions are used to manipulate string values.

Function Description Example Output


strtolower Used to convert all string echo strtolower( 'College'); outputs college
characters to lower case letters
strtoupper Used to convert all string echo strtoupper('dotcom'); outputs DOTCOM
characters to upper case letters
strlen The string length function is used echo strlen('india); 5
to count the number of character
in a string. Spaces in between
characters are also counted
explode Used to convert strings into an $settings = explode(';', Array ( [0] =>
array variable "host=localhost; db=sales; host=localhost [1]
uid=root; pwd=demo"); => db=sales [2] =>
print_r($settings); uid=root [3] =>
pwd=demo )
substr Used to return part of the string. $my_str = 'Tit for Tat';echo Tit ...
It accepts three (3) basic substr($my_str,0, 4).'...';
parameters. The first one is the
string, the second parameter is
the position of the starting point,
and the third parameter is the
number of characters to be
returned.
str_replace Used to locate and replace echo str_replace ('the', that book is very
specified string values in a given 'that', 'the book is very nice
string. The function accepts three nice');
arguments. The first argument is
the text to be replaced, the second
argument is the replacement text
and the third argument is the text
that is analyzed.
strpos Used to locate and return the echo strpos('PHP 4
position of a character(s) within a Programing','Pro');
string. This function accepts two
arguments
str_word_count Used to count the number of echo str_word_count ('This 12
words in a string. is a really long sentence that
I wish to cut short');
ucfirst Make the first character of a echo ucfirst('respect'); Outputs Respect
string value upper case
lcfirst Make the first character of a echo lcfirst('RESPECT'); Outputs rESPECT
string value lower case
Constant in PHP
define() function is used to set a constant
It takes three parameters they are:
1. Name of the constant
2. Value of the constant
3. Third parameter is optional. It specifies whether the constant name
should be case-insensitive. Default is false

Constant string Example


<html>
<body>
<?php
/* Here constant name is ‘Hello’ and ‘Good Morning’ is its
constant value and true indicates the constant value is case-
insensitive */
define("Hello","Good Morning",true);
echo Hello;
?>
</body>
</html>

OUTPUT of the above given Example is as follows:


Good Morning

PHP Example to calculate the area of the circle

<html>
<body>
<?php
// defining constant value PI = 3.14
define("PI","3.14");
$radius=15;
$area=PI*$radius*$radius;
echo "Area=".$area;
?>
</body>
</html>

OUTPUT of the above given Example is as follows:

Area=706.5
Arithmetic Operators
Arithmetic operators allow performing basic mathematical operations
Operator Description Example Result
+ Addition $a = 2 + 5; $a=7
- Subtraction $a = 10 - 2; $a=8
* Multiplication $a = 2 * 5; $a=10
/ Division $a = 15 / 5; $a=3
% Modulus $a = 23 % 7; $a=3.28
++ Increment $a =5; $a=6
$a ++;
-- Decrement $a =5; $a=4
$a --;

Increment and Decrement Operators


Operator Name Description
++$a Pre-increment Increments $a by
one, then returns
$a
$a++ Post-increment Returns $a, then
increments $a by
one
--$a Pre-decrement Decrements $a by
one, then returns
$a
$a-- Post-decrement Returns $a, then
decrements $a by
one

Assignment Operators in PHP


Operator Example Is the same as
= x=y x=y
+= x+=y x=x+y
-= x-=y x=x-y
*= x*=y x=x*y
/= x/=y x=x/y
.= x.=y x=x.y
%= x%=y x=x%y
String Operators in PHP
Operator Name Example Result
. Concatenation $a = "Hello" $b $b = "Hello
= $a . " world!" world!"
.= Concatenation $a = "Hello" $a $a = "Hello
Assignment .= " world!" world!"

PHP Include & PHP Include_once


The “include” php statement is used to include other files into a PHP file.
It has two variations, include and include_once. Include_once is ignored by the PHP
interpreter if the file to be included.

Suppose you are developing a website that contains the same navigation menu
across all the pages.

You can create a common header then include it in every page using the include
statement.

The include statement has the following syntax

<?php
include 'file_name';
?>

Example

• We will create 2 files names


• header.php, index.php

Code of “header.php”

<a href=”/index.php”>HOME</a>

<a href=”/aboutus.php”>ABOUT US</a>

<a href=”/contact”>CONTACT</a>

<a href=”/faq.php”>FAQs</a>
Code of “index.php”

<?php

Include “header.php”;

?>

PHP Require & PHP require_once


The require statement has two variations, require and require_once.

The require/require_once statement is used to include file.

Require_once is ignored if the required file has already been added by any of the four
include statements.

Example

Suppose we are developing a database application. We can create a configuration file


that we can include in all pages that connect to the database using the require
statement.

config.php

Code of “config.php”

<?php

$config['host'] = 'localhost';

$config['db'] = 'my_database';

$config['uid'] = 'root';

$config['password'] = '';

?>

Code of “index.php”

<?php

Require “config.php”;
?>
The if Statement in PHP
If statement executes some code only if a specified condition is true

Syntax:
if (condition) { code to be executed if condition is true; }

The if…else Statement in PHP


If…else statement executes some code if a condition is true and some another code if
the condition is false

Syntax:
if (condition)
{
code to be executed if condition is true;
}
else
{
code to be executed if condition is false;
}

The if…elseif…else Statement in PHP


If…elseif…else statement selects 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;
}
Switch Statement in PHP
Switch statement selects one from multiple blocks of code to be executed
Syntax:
switch (n)
{
case label1:
code to be executed if n=label1;
break;
case label2:
code to be executed if n=label2;
break;
...

default:

code to be executed if n is different from all labels;

For loop in PHP


PHP for loop executes a block of code, a specified number of times

Syntax:
for (initialization; test condition; increment/decrement)
{
code to be executed;
}

Do While loop in PHP


Do while loop will always execute the block of code once, it will then check the
condition, and if the condition is true then it repeats the loop

Syntax:
do
{
code to be executed;
} while (condition );
User Defined Function in PHP
Functions are group of statements that can perform a task

Syntax:
function functionName()
{
code to be executed;
}

PHP Functions -Return values


<html>
<body>
<?php
// Function definition function add($x,$y)
{
$total=$x+$y; return $total;
}
// Function calling
echo "1 + 16 = " . add(1,16);
?>
</body>
</html>

OUTPUT of the above given Example is as follows:


1 + 16 = 17

Break statement
Break statement is used to terminate the loop
After the break statement is executed the control goes to the statement immediately after the loop
containing break statement

Break statement example


<html>
<body>
<?php
/* when $i value becomes 3, the loop is Terminated*/
for($i=0;$i<5;$i++)
{if($i==3)
break;}
else
echo "$i ";?></body></html>
Continue statement
There are cases in which, rather than terminating a loop, you simply want to skip
over the remainder of iteration and immediately skip over to the next. Continue
statement is used to skip a particular iteration of the loop.

Continue statement example


<html>
<body>
<?php
/* when $i value becomes 3, it will skip the
particular of the loop*/
for($i=0;$i<=5;$i++)
{
if($i==3)
continue;

else

echo “$i”;

}
?>
</body>
</html>

OUTPUT of the above


given Example is as
follows:
01245
L.J COLLEGE OF COMPUTER APPLICATIONS
Multidimensional array in PHP

Multidimensional array is an array containing one or more arrays

Multidimensional array Example

<?php
$student=array(
array(1,"Mr. A"),
array(2,"Mr. B"),
array(3,"Mr. C"));
foreach ($student as $key => $i)
{
echo "$key =>";
foreach ($i as $j)
{
echo " $j";
}
echo "</br>";
}
?>

Date() and time() function in PHP


▪ The PHP date() function formats a timestamp to a more readable date and time
▪ A timestamp is a sequence of characters, denoting the date and/or time at which a certain
event occurred
▪ Some characters that are commonly used for date and time:d -
Represents the day of the month (01 to 31)
m - Represents a month (01 to 12) Y -
Represents a year (in four digits)
l (lowercase 'L') - Represents the day of the week
h - 12-hour format of an hour with leading zeros (01 to 12)i -
Minutes with leading zeros (00 to 59)
s - Seconds with leading zeros (00 to 59)
a - Lowercase Ante meridiem and Post meridiem (am or pm)

L.J COLLEGE OF COMPUTER APPLICATIONS


UNIT
1
1. Write a program in PHP to display "Learning PHP" in bold
format.
<?php
echo "<b>Learning PHP</b>";
?>

2. Write a program in PHP to demonstrate the use of comments,


echo
and print.
<?php
echo("below is single line comment<br>");
//echo("this is single line
comment");echo("below is
multiline comment");
/*thi
sis
multiline
comment*
/
echo"<h1>this is use of echo
!</h1>";print"this is use of print";
?>

L.J COLLEGE OF COMPUTER APPLICATIONS


3. Create a program in PHP to demonstrate the use of If … Else
and
switch statements..Along with loops.
i. Sum of digits

L.J COLLEGE OF COMPUTER APPLICATIONS


ii. Check whether number is odd or even

L.J COLLEGE OF COMPUTER APPLICATIONS


iii. Prime number
<?php
$count = 0;
$num = 2;
while ($count < 15 )
{
$div_count=0;
for ( $i=1; $i<=$num; $i++)
{
if (($num%$i)==0)
{
$div_count++;
}
}
if ($div_count<3)
{
echo $num." , ";
$count=$count+1;
}
$num=$num+1;
}
?>

L.J COLLEGE OF COMPUTER APPLICATIONS


iv. Print table of number

L.J COLLEGE OF COMPUTER APPLICATIONS


L.J COLLEGE OF COMPUTER APPLICATIONS
v. Factorial of a number

L.J COLLEGE OF COMPUTER APPLICATIONS


Vi Armstrong number

L.J COLLEGE OF COMPUTER APPLICATIONS


L.J COLLEGE OF COMPUTER APPLICATIONS
Vii Palindrome number using inbuilt function

L.J COLLEGE OF COMPUTER APPLICATIONS


Q. Palindrome Number Without using inbuilt function

Viii Fibonacci series:

L.J COLLEGE OF COMPUTER APPLICATIONS


<?php
$num = 0;
$n1 = 0;
$n2 = 1;
echo "<h3>Fibonacci series for first 12 numbers:
</h3>";echo "\n";
echo $n1.' '.$n2.'
';while ($num <
10 )
{
$n3 = $n2 +
$n1;echo $n3.'
';
$n1 = $n2;
$n2 = $n3;
$num = $num + 1;
}
?>

Ix Reverse Number

L.J COLLEGE OF COMPUTER APPLICATIONS


L.J COLLEGE OF COMPUTER APPLICATIONS
X Reverse string

L.J COLLEGE OF COMPUTER APPLICATIONS


Xi Swap number

L.J COLLEGE OF COMPUTER APPLICATIONS


Xii Number triangle
<?php
for($i=0;$i<=5;$i++
){
for($j=1;$j<=$i;$j++
){echo $j;
}
echo "<br>";
}
?>

Xiii Star triangle


<?php
for($i=0;$i<=5;$i++
){
for($j=1;$j<=$i;$j++
){echo "* ";
}
echo "<br>";} ?>
L.J COLLEGE OF COMPUTER APPLICATIONS
Xiv Check whether sum is even or odd
<?php
$a=array(1,2,3,4,5,8,1);
$sum=0;
for($i=0;$i<count($a);$i++)
$sum +=
$a[$i];
if($sum%2==0)
echo "sum of array element is even : $sum";
else
echo "sum of array element is odd : $sum";
?>

L.J COLLEGE OF COMPUTER APPLICATIONS


Xv Find sum of odd numbers and even numbers from
array.
<?php
$a=array(12,2,32,4,54,8,10);
$sumo=0;
$sume=0;

for($i=0;$i<count($a);$i++)
{
if($a[$i]%2==0)
$sume += $a[$i];
else
$sumo += $a[$i];
}

if($sumo==0)
echo "there are no odd numbers in the array <br>";
else
echo "sum of odd numbers : $sumo
<br>";if($sume==0)
echo "there are no even numbers in the array
<br>";
else
echo "sum of even numbers : $sume";

?>

L.J COLLEGE OF COMPUTER APPLICATIONS


Xvi Print name in pyramid shape

L.J COLLEGE OF COMPUTER APPLICATIONS


Xvii Find largest and smallest from the array.

<?php
$a = array(2,4,1,54,76,2,17,76,1);
$l=0;
for($i=0;$i<count($a);$i++)
{
if($l<$a[$i])
$l=$a[$i];
}
echo "$l is the largest number
<br>";for($i=0;$i<count($a);$i++)
{
if($l>$a[$i])
$l=$a[$i];
}
echo "$l is the smallest number ";

?>

L.J COLLEGE OF COMPUTER APPLICATIONS


xviii Find second largest and second smallest from the
array.
<?php
$a =
array(1,2,3,4,5);
sort($a);
echo "2nd Largest is : ".$a[count($a)-
2];echo "<br>2nd Smallest is: $a[1]";
?>

L.J COLLEGE OF COMPUTER APPLICATIONS


Xix Replace duplicate numbers with 0 in
array.
<?php
$a=array(1,2,3,4,3,2,1);
$j=0;
for($i=0;$i<count($a);$i++)
{
for($j=$i+1;$j<count($a);$j++)
{
if($a[$i]==$a[$j])
$a[$i]=$a[$j]=0;
}
}
for($i=0;$i<count($a);$i++)
echo $a[$i];
?>

L.J COLLEGE OF COMPUTER APPLICATIONS


Xx Accept marks of 5 subjects. Calculate percentage and provide
grade.

L.J COLLEGE OF COMPUTER APPLICATIONS


L.J COLLEGE OF COMPUTER APPLICATIONS
4 Create an array named $sub, assign five elements to it and
displaythe elements assigned using for loop and foreach
statement

<?php
//using for loop

$sub=array("english","hindi","maths","science","art");
for($i=0;$i<5;$i++)
{
echo"$sub[$i]<br>";
}

?>

L.J COLLEGE OF COMPUTER APPLICATIONS


<?php
//using foreach statement
$sub=array("english","maths","art","hindi","gujarati");
foreach($sub as $i)
{
echo"$i<br>";
}
?>

L.J COLLEGE OF COMPUTER APPLICATIONS


5. Create an array named $student, that stores 5 element
bounded to
a different keys and access the same using the key element.
<?php
$student=array(1=>"Mr.A",2=>"Mr.B",3=>"Mr.C",4=>"Mr.D",5=>"M
r.E");
foreach($student as $key=>$i)
{
echo"$key=>$i<br>";
}
?>

L.J COLLEGE OF COMPUTER APPLICATIONS


6. Write a program in PHP to demonstrate the use of
multidimensionalarrays.
<?php
$student=arra
y(
array(1,"Mr.A"
),
array(2,"Mr.B"),
array(3,"Mr.c"));
foreach($student as
$key=>$i)
{
echo "$key=>";
foreach($i as $j)
{
echo "$j";
}echo"<br>";}?>
L.J COLLEGE OF COMPUTER APPLICATIONS
7. Create two functions in PHP, parameterized and non
parameterizedfor implementing string concatenation
operation.
<?php
//parameterized function

Function joinstrings($a,$b)
{
$c=$a." ".$b;
return $c;
}
$a= "welcome";
$b = "good morning";
Echo
joinstrings($a,$b);
?>

L.J COLLEGE OF COMPUTER APPLICATIONS


<?php
//non-parameterized function

Function joinstrings()
{
$a = "Welcome";
$b = "Good Morning ";
$c = $a ." " .
$b;return $c;
}

echo joinstrings();
?>

8. Write a PHP program to display information of PHP in the


browser.
<?php
Phpinfo();
?>

L.J COLLEGE OF COMPUTER APPLICATIONS


9. Write a program in PHP to sort the array of given 5 numbers
in ascending and descending order without using inbuilt
functions.
<?php
$myArray=array(22,34,12,9,10,5);
for($i=0;$i<=5;$i++)
{
for($j=$i;$j<=5; $j++)
{
if ($myArray[$i]>$myArray[$j])
{
$tmp=$myArray[$i];
$myArray[$i]=$myArray[$j];
$myArray[$j]=$tmp;
}
}
}
echo "Array in ascending order :=</br>";
L.J COLLEGE OF COMPUTER APPLICATIONS
for($i=0;$i<6;$i++)
{
echo $myArray[$i] . "</br>";
}
$myArray=array(22,34,12,9,10,5);for($i=0;$i<=5;$i++)
{
for($j=$i;$j<=5; $j++)
{
if ($myArray[$i]<$myArray[$j])
{
$tmp=$myArray[$i];
$myArray[$i]=$myArray[$j];
$myArray[$j]=$tmp;
}
}
}
echo "Array in descending order :=</br>";for($i=0;$i<6;$i++)
{
echo $myArray[$i] . "</br>";
}
?>

L.J COLLEGE OF COMPUTER APPLICATIONS


10. Write a program in PHP to sort the array of given 5
numbers in
ascending and descending order using inbuilt functions.
<?php
$myArray=array(22,34,12,9,10,5);
sort($myArray);
for($i=0;$i<count($myArray);$i++)
echo "$myArray[$i]<br>";
?>

<?php
$myArray=array(22,34,12,9,10,5);
rsort($myArray);
for($i=0;$i<count($myArray);$i++)
echo "$myArray[$i]<br>";?>

L.J COLLEGE OF COMPUTER APPLICATIONS


11. Write a program to count the total number of times a specific
valueappears in an array.
<?php
$myArray=array(9,34,12,9,10,5,9,56,11,9,10,6);
$valuetocount=9;
$totalcount=0;
for($i=0;$i<=11;$i++)
{
if ($myArray[$i] == $valuetocount)
{
$totalcount++;
}
}
echo "Total $valuetocount in Array is $totalcount times";
?>
UNIT 2
PHP FORMS
▪ Scripts will interact with their clients using one of the two HTTP methods. The methods are
GET and POST
▪ When a form is submitted using the GET method, its values are encoded directly in the query
string portion of the URL
▪ When a form is submitted using the POST method, its values will not be displayed the query
string portion of the URL

The $_GET Function


▪ The built-in $_GET function is used to collect values from a form sent with method="get"
▪ Information sent from a form with the GET method is visible to everyone (it will be displayed
in the browser's URL) and has limits on the amount of information to send (max. 100 characters)
▪ This method should not be used when sending passwords or other sensitive information.
However, because the variables are displayed in the URL, it is possible to bookmark the page
▪ The get method is not suitable for large variable values; the value cannot exceed 100
characters

The $_POST Function


▪ The built-in $_POST function is used to collect values from a form sent with method="post"
▪ Information sent from a form with the POST method is invisible to others and has no limits on
the amount of information to send
▪ However, there is an 8 Mb max size for the POST method, by default (can be changed by
setting the post_max_size in the php.ini file)
The functions used to connect web form to the MYSQL
database:
PHP 5 and later can work with a MySQL database using:

• MySQLi extension (the "i" stands for improved)


• PDO (PHP Data Objects)

What is MySQL?
MySQL is an open-source relational database management system (RDBMS). It is the most
popular database system used with PHP.

• The data in a MySQL database are stored in tables which consists of columns and rows.
• 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 database system.It uses standard SQL
• MySQL compiles on a number of platforms.

mysqli_connect():
The mysqli_connect() function in PHP is used to connect you to the database.

mysqli_connect ( "host", "username", "password", "database_name" )


• host: It is optional and it specify the host name or IP address. In case of local server
localhost is used as a genral keyword to connect local server and run the program.
• username: It is optional and it specify mysql username. In local server username
is root.
• Password: It is optional and it specify mysql password.
• database_name: It is database name where operation performs on data. It also
optional.
• It returns an object which represents MySql connection. If connection failed then it
return FALSE.

Example
<?php
mysqli_connect("localhost", "root", "", "DB_1");

if(mysqli_connect_error())
echo "Connection Error.";
else
echo "Database Connection Successfully.";
?>
mysql_select_db():
mysql_select_db to select a database. It returns TRUE on success or FALSE on failure.

mysql_select_db( db_name, connection );

db_name : Required − MySQL Database name to be selected


connection : Optional − if not specified, then the last opened connection by
mysql_connect will be used.

Example
<?php
$host = 'localhost';
$user = 'root';
$pass = '';
$conn = mysqli_connect($host, $user, $pass);

if(! $conn )
{
die('Could not connect: ' . mysql_error());
}

echo 'Connected successfully';


mysqli_select_db( $conn,'Employee' );

mysqli_close($conn);
?>

mysql_query():
Perform query against a database. The results that are returned are stored in the
variable $result.

<?php
$con = mysqli_connect("localhost","root","","DB_1");

if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
exit();
}

// Perform query
if ($result = mysqli_query($con, "SELECT * FROM Emp"))
{
echo "Returned rows are: " . mysqli_num_rows($result);
// Free result set
mysqli_free_result($result);
}

mysqli_close($con);
?>

mysqli_num_rows
Return the number of rows in a result set

Example
<?php
$con=mysqli_connect("localhost","my_user","my_password","my_db");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

$sql="SELECT Eno, EName FROM Emp ORDER BY Eno";

if ($result=mysqli_query($con,$sql))
{
// Return the number of rows in result set
$rowcount=mysqli_num_rows($result);
echo “Total Rows : “ . $rowcount;
// Free result set
mysqli_free_result($result);
}

mysqli_close($con);
?>
mysqli fetch_array()
Fetch a result row as a numeric array and as an associative array.

<?php
$con=mysqli_connect("localhost","root","","DB_1");

if (mysqli_connect_errno()) {

echo "Failed to connect to MySQL: " . mysqli_connect_error();exit();


}

$sql = "SELECT Eno, Ename FROM Emp ORDER BY Eno";


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

while($row = mysqli_fetch_array($result))
{
Echo “No : “. $row[Eno] ;
Echo “Name : “. $row[Ename].”</br>”;
}

// Free result set


mysqli_free_result($result);

mysqli_close($con);
?>

mysqli affected_rows
Return the number of affected rows from different queries.
<?php
$con = mysqli_connect("localhost","root","","DB_1");
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
exit();
}

// Perform queries and print out affected rows


mysqli_query($con, "SELECT * FROM Emp");
echo "Affected rows: " . mysqli_affected_rows($con);

mysqli_query($con, "DELETE FROM Emp WHERE eno>12");


echo "Affected rows: " . mysqli_affected_rows($con);

mysqli_close($con);
?>
UNIT 2 PROGRAMS

1. Create a form containing two input fields (Name, Email_ID) and a submit button. When the
user clicks on submit button, the form data should be sent for processing to PHP file ,which
should display the welcome message with the email_id on the PHP page. Form data should
be sent by HTTP GET/POST method.

<html>
<body>
<form action="v1.php" method="post">
<input type="text" name="name"><br>
<input type="email" name="email"><br>
<input type="submit" name="submit"><br>
</form>
</body>
</html>
IN v1.php
<?php
$con=mysqli_connect("localhost","root","","db_1");
if(!$con)
die('could not connect:'.mysqli_connect_error());
echo"connection successful<br>";

$id=$_POST["pid"];
$qry=mysqli_query($con,'DELETE FROM product WHERE pro_id='.$id);
$result=mysqli_affected_rows($con);
if($result==1)
echo "record deleted successfully";
else
echo "could not delete";
mysqli_close($con);

?>
2. .Write a PHP script for that creates a database named "DB-1"in MySQL.

<?php
$con=mysqli_connect("localhost","root","");
if(!$con)
die('could not connect:'.mysqli_connect_error());
echo "connection successful<br>";

$qry=mysqli_query($con,'create database DB_1');

if($qry)
echo "db success";
else
echo "db error".mysqli_error($con);
mysqli_close($con);

?>
3. Write a PHP script for creating a product table in the specified database with fields Pro_id,
Pro_name, Pro_price, QOH. Also display an acknowledgement for the same.

<?php
$con=mysqli_connect("localhost","root","","db_1");
if(!$con)
die('could not connect:'.mysqli_connect_error());
echo "connection successful<br>";

$qry=mysqli_query($con,'create table product


(
Pro_id INT,
Pro_name VARCHAR(20) NOT NULL,
Pro_price INT NOT NULL,
QOH INT,
PRIMARY KEY(Pro_id)
)
');
if($qry)
echo "table success";
else
echo "table error".mysqli_error($con);
mysqli_close($con);?>
4. Create a form contaning four input fields(Pro_id, Pro_name, Pro_price, QOH) and Submit
button. When the user clicks on the submit button an PHP script should be executed which
inserts the record in the product table.

<html>
<body>
<form action="v4.php" method="post">
product id : <input type="text" name="pid"><br>
product name : <input type="text" name="pname"><br>
product price : <input type="text" name="pprice"><br>
quantity : <input type="text" name="qoh"><br>
<input type="submit" name="submit"><br>
</form>
</body>
</html>
IN v4.php
<?php
if(isset($_POST))
{
$con=mysqli_connect("localhost","root","","db_1");
if(!$con)
die('could not connect :'.mysqli_connect_error());
echo "connection successful<br>";

$id=$_POST["pid"];
$pn=$_POST["pname"];
$pr=$_POST["pprice"];
$qh=$_POST["qoh"];

$qry=mysqli_query($con,"INSERT INTO product


(pro_id,pro_name,pro_price,qoh) values($id,'$pn',$pr,$qh)
");
$result=mysqli_affected_rows($con);
if($result==1)
echo "record inserted successfully<br>";
else
echo "record error".mysqli_error($con);
mysqli_close($con);
}?>
5. Create a form contaning one input field(Pro_id) and a search button. When the user clicks
on the Search button a PHP script should get executed and should display the details of the
product for the Pro_id specified.

<html>
<body>
<form action="v5.php" method="post">
Product ID : <input type="text" name="pid"><br>
<button type="submit">Search</button>
</form>
</body>
</html>

IN v5.php

<?php
if(isset($_POST))
{
$con=mysqli_connect("localhost","root","","db_1");
if(!$con)
die('could not connect:'.mysqli_connect_error());
echo "connection successful<br>";

$id=$_POST["pid"];
$qry=mysqli_query($con,'SELECT * FROM product WHERE pro_id='.$id);
if(mysqli_num_rows($qry)>0)
{
while($row=mysqli_fetch_array($qry))
{
echo "product id :{$row['Pro_id']}<br>".
"product name :{$row['Pro_name']}<br>".
"product price:{$row['Pro_price']}<br>".
"quantity on hand:{$row['QOH']}<br>";
}
}
else
echo "no record found";
mysqli_close($con);
}
?>
6. Create a form contaning two input fields (Pro_id, QOH) and Update button. When the
user clicks on the Update button the quantity of the Pro_id specified should get updated
using a PHP script.

<html>
<body>
<form action="v6.php" method="POST">
Product ID : <input type="text" name="pid"><br>
Quantity : <input type="text" name="qoh"><br>
<button type="submit">UPDATE</button>
</form>
</body>
</html>

IN v6.php

<?php
if(isset($_POST))
{
$con=mysqli_connect("localhost","root","","db_1");
if(!$con)
die('could not connect:'.mysqli_connect_error());
echo "connection successful<br>";

$id=$_POST["pid"];
$qh=$_POST["qoh"];
$qry=mysqli_query($con,'UPDATE product SET QOH='.$qh.' WHERE Pro_id='.$id);
$result=mysqli_affected_rows($con);
if($result==1)
echo"record updated successfully";
else
echo"could not update".mysqli_error($con);
mysqli_close($con);
}
else
echo"no entry found";
?>
7. Create a form contaning one input field(Pro_id) and a Delete button. When the user clicks
on the Delete button a PHP script should get executed and should delete the record of
the product for the Pro_id specified.

<html>
<body>
<form action="v7.php" method="POST">
Product ID : <input type="text" name="pid"><br>
<button type="submit">delete</button>
</form>
</body>
</html>

IN v7.php

<?php
$con=mysqli_connect("localhost","root","","db_1");
if(!$con)
die('could not connect:'.mysqli_connect_error());
echo"connection successful<br>";

$id=$_POST["pid"];
$qry=mysqli_query($con,'DELETE FROM product WHERE pro_id='.$id);
$result=mysqli_affected_rows($con);
if($result==1)
echo "record deleted successfully";
else
echo "could not delete";
mysqli_close($con);

?>
UNIT 3

AJAX

AJAX can be used for interactive communication with a database.

AJAX = Asynchronous JavaScript and XML.

AJAX is a technique for creating fast and dynamic web pages.

AJAX is not a programming language but it is set of technologies to create fast responsive
webpages. No Page Reload / Refresh is done by using AJAX bcoz it does not load whole
page.
AJAX allows web pages to be updated asynchronously by exchanging small amounts of data
with the server behind the scenes. This means that it is possible to update parts of a web
page, without reloading the whole page.

>>>>>>>INSHORT
It (AJAX) does this by updating only part of a web page rather than the whole page. The
asynchronous interactions are initiated by JavaScript.
The purpose of AJAX is to exchange small amounts of data with server without page refresh.
JavaScript is a client side scripting language. It is executed on the client side by the web
browsers that support JavaScript. JavaScript code only works in browsers that have
JavaScript enabled.

L.J COLLEGE OF COMPUTER APPLICATIONS


WHY to use AJAX

• Validation can be performed done as the user fills in a form without submitting it.
This can be achieved using auto completion. The words that the user types in are
submitted to the server for processing. The server responds with keywords that
match what the user entered.
• It can be used to populate a dropdown box depending on the value of another
dropdown box
• Data can be retrieved from the server and only a certain part of a page updated
without loading the whole page. This is very useful for web page parts that load
things like
• Tweets
• Users visiting the site etc.

ABOUT XMLHttpRequest

XMLHttpRequest objects are used to interact with servers.


XMLHTTPRequest object is an API which is used for get data from the server.
It retrieve any type of data such as json, xml, text etc.
It request for data in background and update the page without reloading
page on client side.
XMLHttpRequest has two modes of operation: synchronous and
asynchronous.

L.J COLLEGE OF COMPUTER APPLICATIONS


Steps of XMLHttpRequest

1. Create XMLHttpRequest object

var xhttp = new XMLHttpRequest();

2. xhttp.open(method, URL, true) …. True for async and false for sync OEN()
method specifies the main parameters of the request:
method – HTTP-method. Usually "GET" or "POST". URL – the URL to request, a string, can be
URL object.
This method just place the request.

3. Send request. xhttp.send()


This method opens the connection and sends the request to server.

L.J COLLEGE OF COMPUTER APPLICATIONS


The onreadystatechange Property of XMLHttpRequest
The readyState property holds the status of the XMLHttpRequest.

Property Description
onreadystatechanDefines a function to be called when the readyState property changes
ge
readyState Holds the status of the XMLHttpRequest. 0: request not initialized
(initial state)
1: server connection established ( open() is called) 2: request received
3: processing request (response is loading means data packets are
received) 4: request finished and response is ready (complete status
with data)
Status 200: "OK"
403: "Forbidden" 404: "Page not found"
statusText Returns the status-text (e.g. "OK" or "Not Found")
The onreadystatechange property defines a function to be executed when the readyState
changes. The status property and the statusText property hold the status of the
XMLHttpRequest object.

The onreadystatechange function is called every time the readyState changes. When
readyState is 4 and status is 200, the response is ready:

L.J COLLEGE OF COMPUTER APPLICATIONS


Q. Create php program to get name from user and display that name (characterwise) on
page using AJAX
1. HTML page : to design UI page . <input elements>
2. JS file ( AJAX) …. Will send your input (from html ) to php (logic / business logic )
to execute
3. JS will call php and will bring back the final output

1. .html
2. .ajax
3. .php

HTML File Todayhtml.html


<html>
<head>
<script type="text/javascript" language="javascript" src="todayajax.js">
</script>
</head>
<body>
Enter Name :
<input type="text" id="txtname" onkeyup="showname();">
<div id="d1">
</div>
</body>
</html

L.J COLLEGE OF COMPUTER APPLICATIONS


JS file Todayajax.js
function showname()
{
var xmlhttp = new XMLHttpRequest;
var str = document.getElementById("txtname").value; xmlhttp.open("GET","todayphp.php?a=" +
str, true); xmlhttp.onreadystatechange= function()
{
if ( xmlhttp.readyState==4 && xmlhttp.status == 200)
{
document.getElementById("d1").innerHTML = xmlhttp.responseText;
}
}
xmlhttp.send();
}

Php file Todayphp.php


<?php
$n=$_GET["a"];
echo "welcome user : " . $n;
?>
UNIT 3 PROGRAMS

1. Create a form containing one input field (Name). When the user enters his/her name and
as any key is released , the form should display a welcome message for the user.
Implement using AJAX.
<html>
<head>
<script src="j1.js"></script>
</head>
<body>
Enter string : <input type="text" id="txtname" onkeyup="showdata();">
<div id="info"></div>
</body>
</html>

IN j1.js

function showdata()
{
var xmlhttp = new XMLHttpRequest();
var str = document.getElementById("txtname").value;
xmlhttp.open("GET","j1.php?q=" + str , true);
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4)
{
document.getElementById("info").innerHTML = xmlhttp.responseText;
}
}
xmlhttp.send();
}

IN j1.php
<?php
$n = $_GET["q"];
echo "Welcome user :".$n;
?>
2. .Repeat the above question to demonstrate the use of keydown and keypress events.
<html>
<head>
<script src="j1.js"></script>
</head>
<body>
Enter string : <input type="text" id="txtname" onkeydown="showdata();">
<div id="info"></div>
</body>
</html>

IN j1.js

function showdata()
{
var xmlhttp = new XMLHttpRequest();
var str = document.getElementById("txtname").value;
xmlhttp.open("GET","j1.php?q=" + str , true);
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4)
{
document.getElementById("info").innerHTML = xmlhttp.responseText;
}
}
xmlhttp.send();
}

IN j1.php
<?php
$n = $_GET["q"];
echo "Welcome user :".$n;
?>

<html>
<head>
<script src="j2.js">
</script>
</head>
<body>
Enter string : <input type="text" id="txtname" onkeypress="showdata();">
<div id="info"></div>
</body>
</html>

IN j2.js

function showdata()
{
var xmlhttp = new XMLHttpRequest();
var str = document.getElementById("txtname").value; xmlhttp.open("GET","j2.php?q=" +
str , true);
xmlhttp.onreadystatechange = function()
{
if (xmlhttp.readyState==4)
{
document.getElementById("info").innerHTML = xmlhttp.responseText;
}
}
xmlhttp.send();
}
IN j2.php
<?php
$n = $_GET["q"];
echo "Welcome user :".$n;
?>
3. Write a program for converting a string into uppercase using AJAX.
<html>
<head>
<script src="j3.js"></script>
</head>
<body>
Enter string : <input type="text" id="txtname"><br>
Result string : <input type="text" id="txtresultname"></br>
<input type="submit" name="submit" onclick="showdata();">
</body>
</html>

IN j3.js

function showdata()
{
var xmlhttp = new XMLHttpRequest();
var str = document.getElementById("txtname").value;
xmlhttp.open("GET","j3.php?q=" + str , true);
xmlhttp.onreadystatechange = function()
{
if (xmlhttp.readyState==4)
{
document.getElementById("txtresultname").value = xmlhttp.responseText;
}
}

xmlhttp.send();
}

IN j3.php

<?php
$n = $_GET["q"];
$n1 = strtoupper($n);
echo $n1;
?>
4. Create a form contaning a combobox with some product names as items. Whenever a
user selects a particular product from the combox, it shuold be sent to the server
asynchronously (i.e. without pressing submit button). Implement using AJAX.
<html>
<head>
<script src="j4.js"></script>
</head>
<body>
<select id="cmboptions" onchange="showdata();">
<option>English</option>
<option>Science</option>
<option>Hindi</option>
</select>
<div id="info"></div>
</body>
</html>

IN j4.js

function showdata()
{
var xmlhttp = new XMLHttpRequest();
var str = document.getElementById("cmboptions").value;
xmlhttp.open("GET","j4.php?q=" + str , true);
xmlhttp.onreadystatechange = function()
{
if (xmlhttp.readyState==4)
{
document.getElementById("info").innerHTML = xmlhttp.responseText;
}
}
xmlhttp.send();
}

IN j4.php
<?php
$n = $_GET["q"];
echo "You selected : " . $n;
?>
5. Write a program to demonstrate the example of sending items selected from radio and
checkbox to server asynchronously.
CHECKBOX

<html>
<head>
<script src="j5c.js"></script>
</head>
<body>
<input type="checkbox" name="product" value="Monitor"/>Monitor<br />
<input type="checkbox" name="product" value="Keyboard"/>Keyboard<br />
<input type="checkbox" name="product" value="CPU"/>CPU<br />
<input type="checkbox" name="product" value="Wires"/>Wires<br />
<input type="button" name="g" value="Click" onclick="getselecteditems()"
/><br />

<h1 id="info"></h1>
</body>
</html>

IN j5c.js

function getselecteditems ()
{
var xmlhttp = new XMLHttpRequest();
var r=document.getElementsByName("product");
var product="";
for(var i=0;i<r.length;i++)
{
if(r[i].checked==true)
{
product+=r[i].value+" ";
}
}
xmlhttp.open('GET','j5c.php?checkselect='+product,true);
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 &&xmlhttp.status==200)

{
document.getElementById("info").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.send();
}

IN j5c.php

<?php
$r=$_GET['checkselect'];
$str=explode(" ",$r);
echo "<br>";
echo "total items selected ".count($str);
echo "<br>";
for($i=0;$i<count($str);$i++)
{
echo "Selected item is : ".$str[$i]."<br>";
}
if($r=="")
{

echo "you have not selected any item";


}
else
{
echo "you have selected <span style=color:red;>".$r."</span>";
}
?>
RADIO BUTTON

<html>
<head>
<script src="j5r.js"></script>
</head>
<body>
<input type="radio" name="product" value="Mouse" onclick="selection()"
/>Mouse<br/>
<input type="radio" name="product" value="CPU" onclick="selection()"
/>CPU<br />
<input type="radio" name="product" value="Keyboard"
onclick="selection()"/>Keyboard<br />

<h1 id="info"></h1>
</body>
</html>

IN j5r.js

function selection()
{
var xmlhttp=new XMLHttpRequest();
var r=document.getElementsByTagName('input');
var product;
for(var i=0;i<r.length;i++)
{
if(r[i].type == "radio" && r[i].checked)
{
product =r[i].value;
}
}
xmlhttp.open('GET','j5r.php?radioselect='+ product,true);
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 &&xmlhttp.status==200)
{
document.getElementById("info").innerHTML=xmlhttp.responseText;
}

}
xmlhttp.send();
}

IN j5r.php

<?php
$r=$_GET['radioselect'];
if($r=="")
{
echo "you have not selected any item";

}
else
{
echo "you have selected <u><i>". $r."</i></u>";
}
?>
6. Write a program to validate a blank field and also validate the length
of the data entered(i.e. minimum lenght of 5).
<html>
<head>
<script src="j6.js"></script>
</head>
<body>
Enter string <input type="text" id="strstring" >
<input type="submit" name="submit" onclick="checkString();">
<div id="info"></div>
</body>
</html>

IN j6.js

function checkString()
{

var xmlhttp = new XMLHttpRequest();


var str = document.getElementById('strstring').value;
xmlhttp.open("GET","j6.php?q=" + str,true);
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState == 4 && xmlhttp.status==200)
{
document.getElementById("info").innerHTML = xmlhttp.responseText;
}
}
xmlhttp.send();
}

IN j6.php
<?php
$str=$_GET["q"];
$n = strlen($str);
echo "length of string is ".$n."<br>";
if ($str=='' || $n <5)
{
echo "String is empty OR string should have minimum 5 characters";
}
else
{
echo "String is : " . $str;
}
?>
7. Write a programto validate and Email ID using regular expression
and by using DOM.
<html>
<head>
<script src="j7.js"></script>
</head>
<body>
Enter Email Id : <input type="text" id="emailid">
<input type="submit" name="submit" onclick="checkemail();">
<div id="info"></div>
</body>
</html>

IN j7.js

function checkemail()
{
var strEmail = document.getElementById("emailid").value;
var a= /^[a-zA-Z0-9_]+\@+[a-zA-Z]+\.[a-z]{2,3}$/;
if (a.test(strEmail)==true)
{
document.getElementById("info").innerHTML="Valid Email
Address";
}
else
{
document.getElementById("info").innerHTML="InValid Email
Address";
}
}
8. Write a program that checks a particular stuId already exits in the
student(stuId,stu_name,mob,country) table or not. If stuId exists
then display a message "User Already Exit. Try another stuId". If it
does not exits then add the data in the student table.Implement
using AJAX.
<html>
<head>
<script src="j8.js"></script>
</head>
<body>
Customer ID : <input type="text" id="custid"><br>
Customer Name : <input type="text" id="custname"><br>
Customer Mobile : <input type="text" id="custmob"><br>
Customer Country : <input type="text" id="custcon"><br>
<input type="submit" name="submit" onclick="cust();">
<div id="info"></div>
</body>
</html>

IN j8.js

function cust()
{
var xmlhttp = new XMLHttpRequest();
var cid = document.getElementById("custid").value;
var cname = document.getElementById("custname").value;
var cmob = document.getElementById("custmob").value;
var ccon = document.getElementById("custcon").value;

xmlhttp.open("GET","j8.php?v1="+cid+"&v2="+cname+"&v3="+cmo
b+"&v4="+ccon,true);
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("info").innerHTML=xmlhttp.responseText
;
}
}
xmlhttp.send();
}

IN j8.php [make sure that stuId is primary key ]

<?php
$conn = mysqli_connect("localhost","root","","db_1");
if(!$conn)
die('Could not connect: '.mysqli_connect_error());
echo 'Connected successfully<br/>';

$id=$_GET["v1"];
$name=$_GET["v2"];
$mob=$_GET["v3"];
$country=$_GET["v4"];

$qry=mysqli_query($conn,"SELECT * FROM student WHERE


stuId=".$id);
$r=mysqli_affected_rows($conn);
if($r==1)
echo "User Already Exit. Try another stuId";
else
{
$qry1=mysqli_query($conn,"INSERT INTO
student(stuId,stu_name,mob,country)
VALUES($id,'$name',$mob,'$country')");
$result=mysqli_affected_rows($conn);

if($result==1)
echo "record successfully inserted";
else
echo "could not insert".mysqli_error($conn);
}
mysqli_close($conn);
?>

You might also like