Ad PHP
Ad PHP
}
j) Give any two applications of AJAX.
2. method_exists()
o Purpose: Checks if a method Name: <input type="text"
exists in a class. name="name" value="<?php echo
$_POST['name'] ?? ''; ?>">
o Example:
Age: <input type="text"
php
name="age" value="<?php echo
CopyEdit $_POST['age'] ?? ''; ?>">
echo "Driving";
} <?php
} if ($_SERVER["REQUEST_METHOD"]
== "POST") {
php php
CopyEdit CopyEdit
Example:
// Select the database html
mysqli_select_db($conn, "myDB"); CopyEdit
This script first connects to the <!-- HTML Form -->
MySQL server, creates a database
myDB, and then selects it for further <input id="name">
operations. <button
onclick="sendData()">Submit</butt
on>
d) Explain the AJAX web application
model.
<!-- Placeholder for response -->
<div id="result"></div> 2. Use the $_FILES array to access the
uploaded file.
if (isset($_POST['submit'])) {
e) How to handle file upload in
PHP? $target_dir = "uploads/";
}
function setDetails($color,
} $model) {
php php
CopyEdit CopyEdit
$_SESSION['username'] = 'JohnDoe';
<td>" . $product->color .
// Save XML to file
"</td>
$xml->asXML('product.xml');
<td>" . $product->weight .
PHP script to display 'product.xml' "</td>
in table format:
</tr>";
php
}
CopyEdit
CopyEdit
<input type="text" id="num1"
<!DOCTYPE html>
placeholder="Enter number 1">
<html>
<input type="text" id="num2"
<head> placeholder="Enter number 2">
} }
xhr.send(); ?>
Featu
GET POST
re
e) Differentiate between GET and
POST method. e).
Featu For
GET POST
re For sendi
retrievin ng
Used
g data or sensi
to Usag
non- tive
send e
Used to sensitive data
data
Purpo send requests or
in the
se data in . larger
body
the URL. data.
of the
reque
st.
Q5) Write a short note on any Two
Data of the following:
is
a) Super Global Variables:
hidde
Data is n in Super Global Variables are built-in
Visibi
visible in the global arrays in PHP that can be
lity
the URL. body accessed from any part of the script,
of the regardless of scope.
reque
They are used to handle data coming
st.
from the user or server.
Limited
No Common Super Global Variables:
Data (by URL
practi
Lengt length 1. $_GET – Collects form data sent via
cal
h restrictio the GET method.
limit.
ns). 2. $_POST – Collects form data sent via
Secur Less More the POST method.
ity secure secur 3. $_SESSION – Used to store session
(data is e variables.
visible). (data
is not 4. $_FILES – Contains file upload
visibl information.