Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
8 views

php practical 10

The document outlines a laboratory experiment for Mobile Application Development, focusing on creating web pages with various form controls such as text boxes, radio buttons, check boxes, and buttons. It includes practical questions about GET and POST methods in PHP, as well as exercises demonstrating form handling and arithmetic operations using PHP. The document provides code examples for both displaying results on the same page and redirecting to another page for results.

Uploaded by

aafu202
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

php practical 10

The document outlines a laboratory experiment for Mobile Application Development, focusing on creating web pages with various form controls such as text boxes, radio buttons, check boxes, and buttons. It includes practical questions about GET and POST methods in PHP, as well as exercises demonstrating form handling and arithmetic operations using PHP. The document provides code examples for both displaying results on the same page and redirecting to another page for results.

Uploaded by

aafu202
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

DEPARTMENT OF COMPUTER ENGINEERING

Subject: Mobile Application Development Subject Code: 22619


Semester: 6 Course: CO6I-A
Laboratory No: Name of Subject Teacher:
Name of Student: AFIF IRFAN NAZIR Roll Id: 21203A1005
Experiment No: 10
Title of Experiment Design web page using following form controls. a) Text box b) Radio
button c) Check box d) Button

 Practical Related Question


1. What is the difference between get and post methods?
The main difference between the GET and POST methods is where
the submitted data is located. With GET, the data is included in the
URL of the request, while with POST, the data is included in the
request body.
2. What is the use of isset() function?
The isset() function in PHP is used to determine whether a variable is set and is not
null. It returns a boolean value (true or false) based on whether the variable has been
defined and is not null.

 Exercise Related Question


1. Write a PHP program that demonstrate form element Text box, Radio button, Check
box, Button.
<!DOCTYPE html>
<html>
<head>
<title>Form Example</title>
</head>
<body>
<h1>Form Example</h1>
<form method="post" action="">
<p>
<label for="name">Name:</label>
<input type="text" id="name" name="name" required>
</p>
<p>
<label>Gender:</label>
<input type="radio" id="male" name="gender" value="male">
<label for="male">Male</label>
<input type="radio" id="female" name="gender" value="female">
<label for="female">Female</label>
</p>
<p>
<label>Languages:</label>
<input type="checkbox" id="english" name="languages[]"
value="english">
<label for="english">English</label>
<input type="checkbox" id="french" name="languages[]"
value="french">
<label for="french">French</label>
<input type="checkbox" id="spanish" name="languages[]"
value="spanish">
<label for="spanish">Spanish</label>
</p>
<p>
<button type="submit" name="submit">Submit</button>
</p>
</form>

<?php
if (isset($_POST['submit'])) {
$name = $_POST['name'];
$gender = $_POST['gender'];
$languages = $_POST['languages'];

echo "<p>Thank you for submitting the form, $name.</p>";


echo "<p>Your gender is $gender.</p>";
echo "<p>You know the following languages:</p>";
echo "<ul>";
foreach ($languages as $lang) {
echo "<li>$lang</li>";
}
echo "</ul>";
}
?>
</body>
</html>
2. Perform arithmetic operations using text filed and buttons and result
should be displayed on same page (Use PHP_SELF).
<!DOCTYPE html>
<html>
<head>
<title>Arithmetic Calculator</title>
</head>
<body>
<h1>Arithmetic Calculator</h1>
<form method="post" action="<?php echo
htmlspecialchars($_SERVER["PHP_SELF"]);?>">
<p>
<label for="num1">Number 1:</label>
<input type="text" id="num1" name="num1">
</p>
<p>
<label for="num2">Number 2:</label>
<input type="text" id="num2" name="num2">
</p>
<p>
<button type="submit"
name="add">+</button>
<button type="submit"
name="subtract">-</button>
<button type="submit"
name="multiply">*</button>
<button type="submit"
name="divide">/</button>
</p>
</form>

<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$num1 = $_POST['num1'];
$num2 = $_POST['num2'];
if (isset($_POST['add'])) {
$result = $num1 + $num2;
echo "<p>$num1 + $num2 = $result</p>";
} elseif (isset($_POST['subtract'])) {
$result = $num1 - $num2;
echo "<p>$num1 - $num2 = $result</p>";
} elseif (isset($_POST['multiply'])) {
$result = $num1 * $num2;
echo "<p>$num1 * $num2 = $result</p>";
} elseif (isset($_POST['divide'])) {
if ($num2 == 0) {
echo "<p>Cannot divide by zero.</p>";
} else {
$result = $num1 / $num2;
echo "<p>$num1 / $num2 =
$result</p>";
}
}
}
?>
</body>
</html>
3. Perform arithmetic operations using text filed and buttons and result
should be displayed on another page.
index.php :
<!DOCTYPE html>
<html>
<head>
<title>Arithmetic Calculator</title>
</head>
<body>
<h1>Arithmetic Calculator</h1>
<form method="post" action="result.php">
<p>
<label for="num1">Number 1:</label>
<input type="text" id="num1" name="num1">
</p>
<p>
<label for="num2">Number 2:</label>
<input type="text" id="num2" name="num2">
</p>
<p>
<button type="submit"
name="add">+</button>
<button type="submit"
name="subtract">-</button>
<button type="submit"
name="multiply">*</button>
<button type="submit"
name="divide">/</button>
</p>
</form>
</body>
</html>
result.php :
<!DOCTYPE html>
<html>
<head>
<title>Arithmetic Calculator Result</title>
</head>
<body>
<h1>Arithmetic Calculator Result</h1>

<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$num1 = $_POST['num1'];
$num2 = $_POST['num2'];

if (isset($_POST['add'])) {
$result = $num1 + $num2;
echo "<p>$num1 + $num2 = $result</p>";
} elseif (isset($_POST['subtract'])) {
$result = $num1 - $num2;
echo "<p>$num1 - $num2 = $result</p>";
} elseif (isset($_POST['multiply'])) {
$result = $num1 * $num2;
echo "<p>$num1 * $num2 = $result</p>";
} elseif (isset($_POST['divide'])) {
if ($num2 == 0) {
echo "<p>Cannot divide by zero.</p>";
} else {
$result = $num1 / $num2;
echo "<p>$num1 / $num2 =
$result</p>";
}
}
}
?>
</body>
</html>

You might also like