0% found this document useful (0 votes)
7 views24 pages

PHP Overview: Uses, Features, and Basics

PHP (Hypertext Pre-processor) is a widely used open-source server-side scripting language primarily for web development, enabling the creation of dynamic websites and applications. It supports various databases, integrates with HTML, and is essential for content management systems and e-commerce platforms. Key features include ease of use, platform independence, and support for object-oriented programming, while its control statements, functions, and arrays facilitate efficient coding practices.

Uploaded by

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

PHP Overview: Uses, Features, and Basics

PHP (Hypertext Pre-processor) is a widely used open-source server-side scripting language primarily for web development, enabling the creation of dynamic websites and applications. It supports various databases, integrates with HTML, and is essential for content management systems and e-commerce platforms. Key features include ease of use, platform independence, and support for object-oriented programming, while its control statements, functions, and arrays facilitate efficient coding practices.

Uploaded by

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

1. What is PHP and write its uses?

Ans. PHP(short for Hypertext Pre-processor) is the most widely used open source and general purpose server
side scripting language used mainly in web development to create dynamic websites and applications .

It is a server-side language, meaning scripts written in PHP are executed on the server before the output is
sent to the user’s browser. Renowned for its ease of use, speed, and flexibility, PHP supports databases,
handles dynamic content, and integrates seamlessly with HTML, making it a versatile choice for developers
worldwide.

Uses of PHP
 Web Development

 PHP is a server-side scripting language that generates dynamic page content.


 It integrates seamlessly with HTML, making it easy to embed PHP code directly into
web pages.

 Content Management Systems (CMS)

 Popular CMS platforms like WordPress, Drupal, Joomla, and Shopify are built on
PHP.
 This makes PHP essential for blogs, online stores, and business websites.

 Database Interaction

 PHP supports multiple databases such as MySQL, PostgreSQL, Oracle, and


MongoDB.
 It’s widely used to store, retrieve, and manage user data.

 E-commerce & Business Applications

 PHP powers online shopping platforms, CRM systems (like HubSpot, Salesforce),
and booking systems.
 It handles secure transactions, user authentication, and session management.

 Server-Side Functions

 Processing form data (e.g., login forms, surveys).


 Managing cookies and sessions.
 Sending and receiving emails.
 File handling (uploading, downloading, generating reports).

[Link] the Features of PHP?


 Open-source and free – available at no cost with strong community support.
 Easy to learn and use – beginner-friendly syntax similar to C and Java.

1|Page
 Server-side scripting – executes on the server, sending only output to the client.
 Supports many databases (MySQL, Oracle, etc.) – excellent for dynamic, data-driven
applications.
 Platform independent – runs smoothly on Windows, Linux, macOS, and Unix.
 Fast and efficient – optimized for web applications with quick execution.
 Supports OOP (Object-Oriented Programming) – enables modular, reusable, and scalable
code design.

[Link] do you embedded php in html?


Ans.T o embed PHP in HTML, you need to place the PHP code within special start and end tags
inside a file with a .php file extension. The web server processes the PHP code on the server side and
sends the resulting HTML to the browser.
<!DOCTYPE html>
<html>
<head>
<title>PHP in HTML Example</title>
</head>
<body>
<h1>Welcome to My Website</h1>

<?php
// PHP code goes here
echo "<p>Hello, this text is generated by PHP!</p>";
?>

</body>
</html>

4. what is variable in php ?


Ans.
2|Page
A variable in PHP is a symbol or name used as a container for storing data, such as numbers,
strings, arrays, or objects, that can be referenced and manipulated throughout a script. PHP is
a loosely typed language, so you do not need to declare the data type explicitly; PHP
automatically determines it based on the value assigned.
Syntax :-
$variable_name = value;

Example:-
<?php
$name = "Prakash";
$age = 20;
?>

5. Write the rules of naming variable ?


Ans.
o A variable starts with the $ sign, followed by the name of the variable
o A variable name must start with a letter or the underscore character
o A variable name cannot start with a number
o A variable name can only contain alpha-numeric characters and underscores (A-z, 0-
9, and _)
o Variable names are case-sensitive ($age and $AGE are two different variables)

[Link] is echo and print? Difference between them.


Ans. Echo and print are both language constructs in PHP used to display output on
the screen. They work very similarly and can output strings, variables, and HTML content to
the browser. Both are commonly used throughout PHP code to generate dynamic content.
The main difference between them is that print returns a value of 1 after execution,
which means it can be used inside expressions, while echo doesn't return any value.
Because of this, you can write something like $x = print "Hello"; and the variable $x
will be assigned the value 1, but you cannot do the same with echo as it will produce
an error.

[Link] are constant?how define a constant in php?

3|Page
A constant is an identifier (name) for a simple value that cannot be changed during the
execution of the script. Unlike variables, constants are automatically global and do not use
the $ symbol.

Syntax: define(name, value, case_insensitive)

Code:
<?php
define("GREETING", "Hello World!");
echo GREETING; // Outputs: Hello World!
// Attempting to change the value will result in an error
// define("GREETING", "Goodbye"); // Error: Constant GREETING already defined
?>

8. What is PHP Control Statements?


Ans. The Control Statements in PHP change the flow of execution of statements, and if other
statements get executed are determined by these statements. For controlling the flow of the
program, these statements are beneficial. Usually, the flow of the program is from top to
bottom, but what if we want to execute a snippet of code when the condition satisfied

Types of Control Statements in PHP


1. Conditional/Selection statements
2. Iteration/Loop statements
3. Jump statements

1. Conditional statements in PHP


There are two basic types of the first kind of Control Statement in
PHP(conditional statements) in any programming language,
 IF, ELSE, and ELSEIF Statements
 SWITCH Statement

The if, elseif, and else Statement in PHP


This section will discuss one of the two mentioned conditional statements: the if,
elseif, and else statements. The if statements are used in cases where the condition
is to be checked for a range of values. The syntax for the same looks like this,
Syntax:-
f (condition) {

4|Page
code to be executed if true;
} elseif (condition) {
code to be executed if the first condition is false and the second condition
is true;
} else {
code to be executed in all other cases;
}

2. Loop Statements in PHP


Loop statements are another part of the Control Statement in PHP. When we
want to run a set of code repeatedly for a certain number of times, we use
loop statements instead of adding similar code lines in a script and making the
program more complex. Until the condition remains true, loops run the block
of code present inside it.

While Loop:-
The block of code written inside the while loop will get executed until
the given condition is true.

Syntax:-
while ( given condition is true) {
the block of code that needs to be executed;
}

Do while Loop:-
This app is slightly different from the while loop as this Loop, without
checking any condition, executes the block of code once then runs it.
At the same time, the given condition gives true value. which means
the do-while Loop executes the block of code once even if the
condition is false.

Syntax:-

do {
the code snippet that needs to be executed;
} while(condition is true );

For Loop:-
When we are sure about the number of times we want to run the
specific block of code, we put that code inside for Loop, specifying the
conditions.
Syntax:-
for (init counter; test counter; increment counter) {
the code to be executed for each iteration;
}

5|Page
Foreach Loop:-
When we want to run a block of code for each element in an array, we
use foreach loop.

Syntax:-
foreach ($array as $value) {
code to be executed;
}

3. Jump statements in PHP


Break :-
For jumping out from the loop, we use the break statement. The
execution of the for, while, do-while, switch, and for-each loop is
broken by keyword break. This statement breaks the current flow of the
loop at the specified condition and then continues with the following
line of code outside the loop.

Example:-
<?php
echo " Coding ninja \n";
for ($x = 0; $x < 10; $x++) {
if ($x == 6) {
break;
}
echo "The number is: $x \n";
}
?>

Continue:-
This statement is different from the break statement. It breaks the loops
or skips the execution of code only for the specified condition,
continues with the next iteration of the loop, and continues the loop/
current flow of the program.

Example:-
<?php
echo "Coding ninja \n";
for ($x = 0; $x < 10; $x++) {
if ($x == 2) {
continue;
}

6|Page
echo "The number is: $x \n";
}
?>

[Link] is function in php?


Ans. A function in PHP is a reusable block of code that performs a specific task. Instead
of writing the same code multiple times throughout your program, you can define it once as a
function and call it whenever needed. Functions help organize code, make it more readable,
and reduce repetition. They can accept input values called parameters, process them, and
optionally return a result.

Syntax:-
function functionName(parameters) {
// code to be executed
return value; // optional
}

Example:-
<?php
function greet() {
echo "Hello, welcome to PHP!";
}
greet(); // Calling the function
?>

[Link] is array in php?


Ans. A PHP Array is a fundamental data structure used in programming to
store and organise multiple values under a single variable. It provides a
convenient way to manage and manipulate collections of data, making it an
essential concept in PHP development. Arrays in PHP are versatile and offer

7|Page
flexibility in representing complex data structures. Regardless of whether you
are dealing with a list of names, a collection of user details, or even a
multidimensional database result, arrays can handle these scenarios effectively.

Example :-

$cars = array("Volvo", "BMW", "Toyota");

[Link] between user defined function and built-in


function in php?

Aspect User-Defined Function Built-in Function


Definition Functions written by the programmer Functions already provided by PHP itself
for specific needs
Availabilit Must be declared before use Available instantly without declaration
y
Flexibility Fully customizable (name, parameters, Fixed functionality, cannot be changed
logic)
Examples function greet() { echo strlen(), date(), count(),
"Hello"; } array_push()
Purpose Used when built-in functions don’t Used for common tasks like string
cover a requirement handling, math, date/time

[Link] is call by value and call by reference ?


Call by Value:-
A copy of the variable’s value is passed to the function.
Changes made inside the function do not affect the original value.
<?php
function addFive($num) {
$num = $num + 5;
return $num;
}

$a = 10;
echo addFive($a); // Output: 15
echo $a; // Output: 10 (unchanged)
?>

8|Page
Call by Reference:-
Instead of a copy, the actual variable reference is passed.
Changes inside the function directly modify the original value.
In PHP, reference is passed using &.

<?php
function addFive(&$num) {
$num = $num + 5;
}

$a = 10;
addFive($a);
echo $a; // Output: 15 (changed)
?>

[Link] are the types of array ?


Ans .
Indexed Arrays

These arrays use numeric keys that start from 0. They are suitable when the order of elements
is important and you don’t need custom labels for keys.

Example: array("Apple", "Mango", "Banana")

Associative Arrays

These arrays use string keys defined by the programmer. They are useful when you want to
map values to meaningful identifiers, creating a key–value relationship.

Example: "name" => "John"

Multidimensional Arrays

These arrays contain other arrays as elements. They allow representation of complex data
structures such as tables, matrices, or hierarchical information.

Example:- $marks = array(


array(90, 85, 88),
array(78, 80, 82)
);

[Link] to short an array ?


<?php
$numbers = array(40, 10, 30, 20);

9|Page
// sort function sorts in ascending order
sort($numbers);

foreach ($numbers as $value) {


echo $value . " ";
}
?>

[Link] is the difference between require and


include in php?
The difference between require() and include in PHP is that require() stops script execution
with a fatal error if the file is missing, while include only produces a warning and allows the
script to continue running

include
<?php
echo "Start of script<br>";

// File does not exist


include "[Link]";

echo "This line will still run<br>";


echo "End of script";
?>

require
<?php
echo "Start of script<br>";

// File does not exist


require "[Link]";

echo "This line will NOT run<br>";


echo "End of script";
?>

[Link] is global variable in php?


A global variable in PHP is a variable declared outside of all functions or classes, making it
accessible throughout the script. However, inside functions it is not automatically available

10 | P a g e
unless you explicitly declare it with the global keyword or access it through the special
$GLOBALS array.

Example:-
<?php
$x = 5;

function showValue() {
global $x;
echo $x;
}

showValue(); // Output: 5
?>

[Link] is super global variable in php ?and provide


list of the superglobal variable ?
[Link] superglobals are predefined variables that are globally available in all scopes.
They are used to handle different types of data, such as input data, server data, session data,
and more. These superglobal arrays allow developers to easily work with these global data
structures without the need to declare them globally.
List of PHP Superglobal Variables

PHP provides the following superglobals:

$GLOBALS – stores all global variables

$_SERVER – server & environment information

$_REQUEST – collects form data (GET + POST + COOKIE)

$_POST – data sent using POST method

$_GET – data sent from URL/query string

$_FILES – file uploads

$_COOKIE – cookies set by the browser

$_SESSION – user session variables

$_ENV – environment variables

11 | P a g e
Example :-
<?php
echo $_SERVER['PHP_SELF']; // Current script name
echo $_SERVER['SERVER_NAME']; // Server host name
?>

[Link] is a get method how does it sends data ?


what is post method ?why more secure ?

GET Method in PHP


 Definition: The GET method is an HTTP request method used to send data from the client (browser)
to the server by appending it to the URL as query parameters.

POST Method in PHP


 Definition: The POST method is another HTTP request method used to send data from the client to
the server, but it sends the data in the HTTP request body, not in the URL.

Why POST is More Secure


 Visibility: Unlike GET, POST does not expose data in the URL, so sensitive information (like
passwords) is not visible in browser history, bookmarks, or server logs.
 Data Size: POST can handle larger amounts of data, including files.
 Control: POST requests are less likely to be cached or accidentally shared compared to GET requests.

Example:-

<!DOCTYPE html>
<html>
<head>
<title>GET and POST Example</title>
</head>
<body>

<h2>Using GET and POST in the Same PHP Program</h2>

<!-- GET Form -->


<form method="GET" action="">
<label>Enter Your Name (GET):</label>
<input type="text" name="name">

12 | P a g e
<input type="submit" value="Submit GET">
</form>

<br><br>

<!-- POST Form -->


<form method="POST" action="">
<label>Enter Your Age (POST):</label>
<input type="text" name="age">
<input type="submit" value="Submit POST">
</form>

<hr>

<?php
// Handling GET request
if (isset($_GET['name'])) {
$name = $_GET['name'];
echo "<h3>Value received using GET:</h3>";
echo "Name: " . $name . "<br>";
}

// Handling POST request


if (isset($_POST['age'])) {
$age = $_POST['age'];
echo "<h3>Value received using POST:</h3>";
echo "Age: " . $age . "<br>";
}
?>

</body>
</html>

 19. what is isset?why do you using in form ?


The isset() function in PHP checks whether a variable is declared and not NULL. It returns
true if the variable exists and has a non-NULL value, and false otherwise, without modifying
the variable.

Syntax:-
bool isset( mixed $var [, mixed $... ] )

Why is isset() used in forms :-

When working with forms, you often need to verify whether the user has submitted data.

 Form submission check:


isset() is used to confirm if a form field or the submit button has been set before

13 | P a g e
processing.
Example:
 if (isset($_POST['submit'])) {
 // Process form data
 }

This ensures the code runs only when the form is actually submitted.

 Avoiding errors:
Without isset(), trying to access an undefined variable (like $_POST['name'] before
submission) can cause warnings.
Using isset() prevents these warnings by checking existence first.
 Validation:
It helps in validating whether required fields are present before using their values.

[Link] is file handling in php?


=In PHP, File handling is the process of interacting with files on the server, such as reading files,
writing to a file, creating new files, or deleting existing ones. File handling is essential for
applications that require the storage and retrieval of data, such as logging systems, user-generated
content, or file uploads.

[Link] fopen(),fclose(),fwrite(),fread() with


example?
The fopen() function in PHP is used to open a file or URL. It returns a file pointer that can be
used with other functions like fread(), fwrite(), and fclose(). The function allows developers to
interact with files in various ways, including reading, writing, and appending data.

Syntax:-fopen(filename, mode)

$myfile = fopen("[Link]", "w");


fwrite($myfile, "Hello PHP File Handling!");

fread() : fread() method is used when we want to read the file in limited size. We pass the limit in
bytes in fread() method, and the method then reads the file to that limit and leave the remaining
part of the file.
Syntax: fread(file_pointer, length)

$myfile = fopen("[Link]", "r");


$content = fread($myfile, filesize("[Link]"));
echo $content;

14 | P a g e
The fwrite() function in PHP is used to write data (string or binary) to an open file. Before using
fwrite(), you need to open the file with fopen(). Once the file is open, fwrite() sends your data to
that file.

Syntax: fwrite(file_pointer, string, length)

$myfile = fopen("[Link]", "w");


fwrite($myfile, "Hello PHP File Handling!");

The fclose() function in PHP closes an open file pointer, ensuring all buffered data is flushed to
disk and system resources are released.

Syntax:fclose(file_pointer)

Example :-
<?php
// Example 1: Writing to a file
$filename = "[Link]";

// Open file for writing (creates if doesn't exist)


$file = fopen($filename, "w");

if ($file) {
$content = "Hello, this is a test file.\n";
$content .= "Writing multiple lines.\n";

// Write to file
$bytes_written = fwrite($file, $content);
echo "Wrote $bytes_written bytes to file.\n";

// Close the file


fclose($file);
} else {
echo "Error opening file for writing.";
}

15 | P a g e
// Example 2: Reading from a file
$file = fopen($filename, "r");

if ($file) {
// Get file size to read entire content
$filesize = filesize($filename);

// Read entire file content


$content = fread($file, $filesize);
echo "File content:\n$content\n";

// Close the file


fclose($file);
} else {
echo "Error opening file for reading.";
}

// Example 3: Appending to a file


$file = fopen($filename, "a");

if ($file) {
$new_content = "This line is appended.\n";
fwrite($file, $new_content);
fclose($file);
echo "Content appended successfully.\n";
}

// Example 4: Reading file line by line


$file = fopen($filename, "r");

16 | P a g e
if ($file) {
echo "\nReading line by line:\n";
while (!feof($file)) {
$line = fgets($file); // reads one line
echo $line;
}
fclose($file);
}

// Example 5: Binary file operations


$binary_file = "[Link]";
$file = fopen($binary_file, "wb"); // 'b' flag for binary mode

if ($file) {
$data = pack("S*", 65, 66, 67); // Pack some binary data
fwrite($file, $data);
fclose($file);
}

// Read binary data


$file = fopen($binary_file, "rb");
if ($file) {
$data = fread($file, 6); // Read 6 bytes
$unpacked = unpack("S*", $data);
print_r($unpacked);
fclose($file);
}
?>

[Link] a program to create and write to a file

17 | P a g e
<?php
// File name
$filename = "[Link]";

// Content to write
$content = "Hello World!\nThis file is created using PHP.";

// Open file in write mode


$file = fopen($filename, "w");

if ($file) {
// Write content to file
fwrite($file, $content);

// Close the file


fclose($file);

echo "File created and written successfully.";


} else {
echo "Unable to create the file.";
}
?>

23. How do you read a file line by line?


<?php
$filename = "[Link]";

// Open file in read mode


$file = fopen($filename, "r");

if ($file) {
// Read file line by line
while (($line = fgets($file)) !== false) {
echo $line . "<br>";
}

// Close the file


fclose($file);
} else {
echo "Unable to open the file.";
}
?>

[Link] between r, w, a file modes


Read Mode ('r')

 Opens file for reading only


 File pointer positioned at the beginning
 File must exist or fopen() returns false
 Cannot write to the file
 Use case: Reading data, configuration files

Write Mode ('w')

18 | P a g e
 Opens file for writing only
 File pointer at the beginning
 Truncates file to zero length (erases all existing content)
 Creates file if it doesn't exist
 Cannot read from the file
 Use case: Creating new files, completely replacing content

Append Mode ('a')

 Opens file for writing only


 File pointer at the end of file
 Preserves existing content - adds new data at the end
 Creates file if it doesn't exist
 Cannot read from the file
 Use case: Log files, adding records without losing existing data

[Link] is File uploading in php?


File uploading in PHP is the method of transferring a file from a user’s computer to a server
using an HTML form and PHP script. The uploaded file is first stored in a temporary location and
then moved to a permanent directory with functions like move_uploaded_file().

<form action="[Link]" method="POST" enctype="multipart/form-data">


<input type="file" name="myfile">
<input type="submit" value="Upload">
</form>

<?php
$filename = $_FILES["myfile"]["name"];
$tempname = $_FILES["myfile"]["tmp_name"];
$folder = "uploads/".$filename;

if (move_uploaded_file($tempname, $folder)) {
echo "File uploaded successfully!";
} else {
echo "File upload failed.";

19 | P a g e
}
?>

[Link] is cookie ? how do you set & retrieve a cookie


in php ?
Ans. A cookie is a small pieces of data stored on the user browser . It is used to remember
information like username , language preferences or items in a card

How to set a cookie in php :-


<?php
setcookie("username", "Rahul", time() + 3600); // expires in 1 hour
?>
How to retrieve a cookie :-
<?php
echo $_COOKIE["username"];
?>

[Link] is a session how it use ?


Ans. A session is way to store user information on the server for later use .
Why it use :-
i) To keep lock in
ii) To store temporary data securely
iii) To track user actively in a website
iv) Section are more secure than cookie data is store on the server hot the browser

Session start :-

<?php
session_start(); // Start the session

// Store session data


$_SESSION["username"] = "Rahul";

20 | P a g e
$_SESSION["course"] = "BCA";

echo "Session variables are set successfully!";


?>

Session display :-

<?php
session_start(); // Continue the session

// Check if session variables exist


if(isset($_SESSION["username"])) {
echo "Username: " . $_SESSION["username"] . "<br>";
echo "Course: " . $_SESSION["course"];
} else {
echo "No session data found.";
}
?>

Session destroy :-
<?php
session_start(); // Continue the session
session_unset(); // Remove all session variables
session_destroy(); // Destroy the session

echo "Session destroyed successfully!";


?>

[Link] is php MYSQL integration ?


The Importance of PHP and MySQL Integration
The integration of PHP and MySQL allows developers to create complex web applications
with dynamic content. This combination facilitates tasks like:

 Data storage and retrieval

 User authentication and management

 Data manipulation through CRUD operations (Create, Read, Update, Delete)

 Scalability and performance optimization

[Link] is Mysql commonly used in php ?

21 | P a g e
MySQL is commonly used with PHP because they integrate seamlessly, are free and open-source,
and together provide a powerful, efficient way to build dynamic, database-driven websites.

Why MySQL is Popular with PHP

1. Seamless Integration
PHP and MySQL were designed to work together smoothly. PHP has built-in functions (`mysqli`,
`PDO`) that make connecting to and querying MySQL databases straightforward.

2. Open-Source & Cost-Effective


Both PHP and MySQL are free, open-source technologies. This makes them highly attractive for
startups, students, and enterprises looking to minimize costs.

3. Performance & Efficiency


MySQL is a robust relational database management system (RDBMS) that efficiently stores and
retrieves data. Combined with PHP’s lightweight execution, they deliver fast performance for web
applications.

4. Large Community & Support


PHP and MySQL have massive developer communities, extensive documentation, and countless
tutorials. This makes troubleshooting and learning easier for beginners and professionals alike.

5. Cross-Platform Compatibility
Both run on multiple operating systems (Windows, Linux, macOS), making them flexible for
deployment across different environments.

[Link] is the purpose of database connection in php?


The purpose of a database connection in PHP** is to allow PHP scripts to interact with a database
(like MySQL) so that websites and applications can store, retrieve, update, and manage data
dynamically.

Purposes of Database Connection in PHP

1. Data Storage & Retrieval


Connects PHP to a database so information (e.g., user details, products, blog posts) can be saved
and fetched when needed.

2. Dynamic Content Generation


Enables websites to display personalized or updated content (e.g., showing latest news, user
profiles, or shopping cart items).

22 | P a g e
3. Data Manipulation
Allows PHP scripts to insert, update, delete, and modify records in the database.

4. User Interaction
Supports features like login systems, registration forms, and feedback submissions by validating
and storing user input.

5. Backend Integration
Acts as the bridge between the front-end (what users see) and the backend database, ensuring
smooth communication.

[Link] the basic step to connect php with MYSQL


database ?

<!DOCTYPE html>
<html>
<head>
<title>Insert Data using PHP & MySQL</title>
</head>
<body>

<h2>Student Registration Form</h2>

<form method="post">
Name: <input type="text" name="name" required><br><br>
Email: <input type="email" name="email" required><br><br>
<input type="submit" name="submit" value="Insert">
</form>

<?php
// Database connection
$conn = mysqli_connect("localhost", "root", "", "studentdb");

// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}

// Insert data
if (isset($_POST['submit'])) {
$name = $_POST['name'];
$email = $_POST['email'];

23 | P a g e
$sql = "INSERT INTO student(name, email) VALUES ('$name', '$email')";

if (mysqli_query($conn, $sql)) {
echo "<br>Data inserted successfully";
} else {
echo "Error: " . mysqli_error($conn);
}
}

// Close connection
mysqli_close($conn);
?>

</body>
</html>

32. What is SQL query ? how is it executed using php?

24 | P a g e

You might also like