Practical Questions Answers
Practical Questions Answers
2.VWritea script to keep track of a number of times the web page has been accessed using
the Session.
Display all movies and released year acted by any actor or actress in tabular format
4.Write a PHP script to check mobile number entered by the user is valid or not and display
an appropriate message.
5.Write a PHP Script to create a class Book (Book_id, Book_name, Publication, Book_price)
and Author (aid,auth name) is child class Write a member function to accept and display
Book and author details.
7.Write a PHP Script to accept two numbers from user which will perform the Addition,
Subtraction, Multiplication, and Division of two numbers as per the choice. (Use Switch
Case and radio button )
8.Write a PHP Script to define interface and calculate the area of Circle, Square, and
Rectangle display result
9.Write a PHP script to accept customer name and the list of product and quantity on the
first page. On the next page display the name of the customer, name of the products, rate
of the product, quantity, and total price in table format.
10.Write a PHP script to accept string from user and check is it palindrome or not?use self
processing form and string function
11.Write a PHP Script to create a class Fruit that contains constructor to accept data
members as Name, Color and Price. Write a member function to accept and display details
of Fruit.
12.Write a PHP script to convert temperature Fahrenheit to celsious use sticky forms to
accept temperature
<?php
If ($ SERVER["REQUEST METHOD" ] == "POST") {
= $
POST['url'1;
$url
?>
<form method="post">
Enter website URL: <input type="text"
name="url">
<input type="submit" value="Submit">
</form>
<?php
Session start () ;
<?php
= [
$movies
['m no' => 1, 'm name' => Inception'
'releaseyear' => 2010, 'actor' => Leonardo
DiCaprio'],
[ 'm no => 2, 'm name' => The Matrix',
*releaseyear' => 1999, 'actor' => Keanu
ReevesJ,
[ 'm no => 3, 'm name => Titanic',
'releaseyear' => 1997, actor! => Leonardo
DiCaprio']
Echo
"<trs<td>{$movie m name'] }</td><td>{$movie['rel
[
easeyear'l}</td><td>{ Smovie [ 'actor' l }</td></tr>"
Echo "</table>";
?>
<?php
If ($ SERVER[ "REQUEST METHOD" ] "POST") {
= POST [ 'mobile'];
mobile $
If (preg match ('/^[6-9] [0-9] {9}$/',
) {
mobile)
Echo "Valid Mobile Number";
}
else {
Echo "Invalid Mobile Number" ;
}
?>
<form method="post">
Enter Mobile Number: <input type="text"
name="mobile">
<input type="submit" value="Submit">
</form>
<?php
{
Class Book
Public book id, $book name, $publication,
$book price;
{
Class Author extends Book
Public $author id, $author name;
Function displayAuthorDetails () {
$this->displayDetails () ;
Echo "Author ID: $this->author id <br>
Author Name: $this->author name <br>";
}
,
$book = new Author (1, PHP Basics', Pearson'
500, 101, 'John Doe'):
$book->displayAuthorDetails ();
?>
<?php
$array = [10, -20, 30, -40, 50]:
If ($element >= 0) {
Echo "$element is Positive<br>";
}
else {
Echo "$element is Negative<br>";
}
{
Switch ($operation)
Case "add":
+ ;
Echo "Result: ($num1 num2)
Break;
Case "subtract":
Echo "Result: ($num1 $num2);
Break;
Case multiply":
*
Echo "Result: ($numl $num2);
Break;
Case divide":
;
Echo "Result: ($numl / $num2)
Break;
?>
<form method="post">
Enter First Number: <input type="number"
name="num1"><br>
Enter Second Number: <input type="number"
name="num2 "><br
<input type="radio" name="operation"
value="add">Addition
<input type="radio" name="operation"
value="subtract">Subtraction
<input type-" radio" name-"operation"
value="multiply">Multiplication
<input type="radio" name="operation"
value="divide">Division<br
<input type="submit" value="Submit">
</form>
<?php
interface Shape {
{
class Circle implements Shape
private $radius;
$this->radius = $radius;
}
private $side;
$this->side = $side;
{
class Rectangle implements Shape
private $length, $width;
$this->length = $length;
$this->width = $width;
}
<?php
if ($ SERVER["REQUEST METHOD"] == "POST") {
$total = 0;
echo
"<tr><td>$product</td><td>$quantity</td><td>$rat
e</td><td>$price</td></tr>";
}
echo "<tr>td
colspan=13'>Total</td><td>$total</td></tr</tabl
e>";
}
?>
<form method="post">
Customer Name: <input type="text"
name="customer name"><br>
Product 1: <input type="text"
name"product ]"><br>
Quantity 1: <input type="number"
name=" quantity [] "><br>
Product 2: <input type="text"
name="product [] "><br>
Quantity 2: <input type="number"
name=" quantity [] "><br>
<input type=" submit" value="Submit">
</form>
10. PHP Script to Check if a String is
Palindrome (Self Processing Form)
<?php
if ($ SERVER["REQUEST METHOD" ] "POST") {
if ($processedString
strrev ($processedstring) ) {
?>
<form method="post">
Enter a String: <input type="text"
name="string" value="<?php echo
isset ($ POST('string']) ? $ POST'string']:;
?>">
<input type="submit" value="Check">
</form>
11. PHP Script to Create a Class Fruit with
Constructor and Display Details
<?php
{
class Fruit
public $name, $color, $price;
public
{
function Construct ($name, $color,
$price)
$this->name $name;
$this->color = $color;
$this->price= $price;
}
= new
$apple Fruit ("Apple", "Red", 150);
$apple->displayDetails () ;
?>
12. PHP Script to Convert Temperature from
Fahrenheit to Celsius Using Sticky Form
<?php
{
function fahrenheitToCelsius ($fahrenheit)
return ($fahrenheit - 32) * 5 / 9;
}
?>
<form method="post">
Enter Temperature in Fahrenheit:
<input type-"number" name-"fahrenheit"
value"<?php echo isset: ($ POST ['fahrenheit']) ?
$ POST['fahrenheit'] "; ?>">
<input type="submit" value="Convert ">
</form>