Test 2 Solution
Test 2 Solution
Q.2. A) Write difference between get() and post() method of form (Any two points) (02 Marks)
get() post()
In GET method we cannot send large amount In POST method large amount of data
of data rather limited data is sent because the
can be sent because the request parameter
request parameter is appended into the URL. is appended into the body
GET request is comparatively better than Post
POST request is comparatively less
so it is used more than the Post request. better than Get so it is used less than the
Get request.
GET request is comparatively less secure POST request is comparatively more
because the data is exposed in the URL bar. secure because the data is not exposed in
the URL bar
Request made through GET method are Request made through POST method is
stored in Browser history. not stored in Browser history.
Request made through GET method are Request made through POST method
stored in cache memory of Browser. are not stored in cache memory of
Browser
Q.3. A) How do you connect MYSQL database with PHP write its syntax also (02 Marks)
<?php
$servername = "localhost";
$username = "";
$password = "";
// Create connection Object Oriented
$conn = new mysqli($servername, $username, $password);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
?>
Q.3. B) Attempt any One of the following. (04Marks)
a) Write PHP program for update operation on table data?
(Any data can be considered for updation)
<?php
$servername = "localhost";
$username = "";
$password = "";
$dbname = "yDB";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "UPDATE MyGuests SET lastname='Doe' WHERE id=2";
if ($conn->query($sql) === TRUE) {
echo "Record updated successfully";
} else {
echo "Error updating record: " . $conn->error;
}
$conn->close();
?>
b) Write PHP program for, select operation on table data.
(Any data can be considered for selecting records)
<?php
$servername = "localhost";
$username = "";
$password = "";
$dbname = "yDB";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT id, firstname, lastname FROM MyGuests";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo "id: " . $row["id"]. " - Name: " . $row["firstname"]. " " . $row["lastname"].
"<br>";
}
} else {
echo "0 results";
}
$conn->close();
?>