Keshav PHP
Keshav PHP
PRACTICAL FILE
OF
Open Source Technologies Using PHP
INDEX
PRACTICAL - 1
Once the software bundle has been downloaded, you can start the installation by
double clicking on the file with the ending .exe.
Since an active antivirus program can negatively affect the installation process, it’s
recommended to temporarily pause any antivirus software until all XAMPP
components have successfully been installed.
User Account Control (UAC) can interface with the XAMPP installation because it
limits writing access to the C: drive, so we recommend you deactivate this too for the
duration of the installation process.
After you have opened the .exe file (after deactivating your antivirus program(s) and
taken note of the user account control, the start screen of the XAMPP setup wizard
should appear automatically. Click on ‘Next’ to configure the installation settings.
‘Select Components’, you have the option to exclude individual components of the
XAMPP software bundle from the installation. But for a full local test server, we
recommend you install using the standard setup and all available components.
In this next step, you have the chance to choose where you’d like the XAMPP
software packet to be installed. If you opt for the standard setup, then a folder with
name XAMPP will be created under C:\ for you. After you’ve chosen a location, click
‘Next’.
Once all the aforementioned preferences have been decided, click to start the
installation. The setup wizard will unpack and install the selected components and
save them to the designated directory. This process can take several minutes in
total. You can follow the progress of this installation by keeping an eye on the green
loading bar in the middle of the screen.
Your Firewall may interrupt the installation process to block the some components of
the XAMPP. Use the corresponding check box to enable communication between
the Apache server and your private network or work network. Remember that
making you XAMPP server available for public networks isn’t recommended.
Once all the components are unpacked an installed, you can close the setup wizard
by clicking on ‘Finish’. Click to tick the corresponding check box and open the
XAMPP Control Panel once the installation process is finished.
PRACTICAL- 2
<html>
<head>
<title>JavaSctipt Calculator</title>
<script>
functioncalcNumbers(result){
</script>
</head>
<body>
<div class="container">
<form name="form">
<div class="display">
</div>
<div class="buttons">
<div class="row">
</div>
<div class="row">
</div>
<div class="row">
<div class="row">
</div>
</div>
</form>
</div>
</body>
</html>
OUTPUT :
PRACTICAL- 3
AIM: Design and develop an input form and validate the fields.
<!DOCTYPE html>
<html>
<head>
<style>
.error {color: #FF0001;}
</style>
</head>
<body>
<?php
$nameErr = $emailErr = $mobilenoErr = $genderErr = $websiteErr = $agreeErr = "";
$name = $email = $mobileno = $gender = $website = $agree = "";
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if (emptyempty($_POST["name"])) {
$nameErr = "Name is required";
} else {
$name = input_data($_POST["name"]);
if (!preg_match("/^[a-zA-Z ]*$/",$name)) {
$nameErr = "Only alphabets and white space are allowed";
}
}
if (emptyempty($_POST["email"])) {
$emailErr = "Email is required";
} else {
$email = input_data($_POST["email"]);
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$emailErr = "Invalid email format";
}
}
if (emptyempty($_POST["mobileno"])) {
$mobilenoErr = "Mobile no is required";
} else {
$mobileno = input_data($_POST["mobileno"]);
if (!preg_match ("/^[0-9]*$/", $mobileno) ) {
$mobilenoErr = "Only numeric value is allowed.";
}
if (strlen ($mobileno) != 10) {
$mobilenoErr = "Mobile no must contain 10 digits.";
}
}
if (emptyempty($_POST["website"])) {
$website = "";
} else {
$website = input_data($_POST["website"]);
if (!preg_match("/\b(?:(?:https?|ftp):\/\/|www\.)[-a-z0-9+&@#\/%?=~_|!:,.;]*[-a-z0-
9+&@#\/%=~_|]/i",$website)) {
$websiteErr = "Invalid URL";
}
}
if (emptyempty ($_POST["gender"])) {
$genderErr = "Gender is required";
} else {
$gender = input_data($_POST["gender"]);
}
if (!isset($_POST['agree'])){
$agreeErr = "Accept terms of services before submit.";
} else {
$agree = input_data($_POST["agree"]);
}
}
function input_data($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
?>
<h2>Registration Form</h2>
<span class = "error">* required field </span>
<br><br>
<form method="post" action="<?php echo htmlspecialchars($_SERVER[
"PHP_SELF"]; ?>" >
Name:
<input type="text" name="name">
<span class="error">* <?php echo $nameErr; ?> </span>
<br><br>
E-mail:
<input type="text" name="email">
<span class="error">* <?php echo $emailErr; ?> </span>
<br><br>
Mobile No:
<input type="text" name="mobileno">
<span class="error">* <?php echo $mobilenoErr; ?> </span>
<br><br>
Website:
<input type="text" name="website">
<span class="error"><?php echo $websiteErr; ?> </span>
<br><br>
Gender:
<input type="radio" name="gender" value="male"> Male
<input type="radio" name="gender" value="female"> Female
<input type="radio" name="gender" value="other"> Other
<span class="error">* <?php echo $genderErr; ?> </span>
<br><br>
Agree to Terms of Service:
<input type="checkbox" name="agree">
<span class="error">* <?php echo $agreeErr; ?> </span>
<br><br>
<input type="submit" name="submit" value="Submit">
<br><br>
</form>
<?php
if(isset($_POST['submit'])) {
if($nameErr == "" && $emailErr == "" && $mobilenoErr == "" && $genderErr == "" &&
$websiteErr == "" && $agreeErr == "") {
echo "<h3 color = #FF0001> <b>You have sucessfully registered.</b> </h3>";
echo "<h2>Your Input:</h2>";
echo "Name: " .$name;
echo "<br>";
echo "Email: " .$email;
echo "<br>";
echo "Mobile No: " .$mobileno;
echo "<br>";
echo "Website: " .$website;
echo "<br>";
echo "Gender: " .$gender;
} else {
echo "<h3> <b>You didn't filled up the form correctly.</b> </h3>";
}
}
?>
</body>
</html>
Output:
PRACTICAL- 4
AIM: Design and develop a dynamic web page which accepts the
marks of the students to display the calculated result with marks
and percentage of the student.
<html>
<body>
<form action="" method="post">
<center>
<table border=0>
<tr>
<td>
Student Name
</td>
<td>
<input type='text' name="name" placeholder="Name of Student">
</td>
</tr>
<tr>
<td>
Marks for Machine Learning
</td>
<td>
<input type='text' name="machinelearning" placeholder="MACHINE LEARNING">
</td>
</tr>
<tr>
<td>
Marks for BlockChain
<td>
<input type='text' name="blockchain" placeholder="BLOCKCHAIN">
</td>
</tr>
<tr>
<td>
Marks for Internet of Things
</td>
<td>
<input type=text name="internetofthings" placeholder="INTERNET OF THINGS">
</td>
</tr>
<tr>
<td>
</table>
<br>
<br>
<input type='submit' name="submit" value="Result">
</center>
<?php
if(isset($_POST["submit"]))////checking whether the input element is set or not
{
$name=$_POST['name']; //accessing value from 1st text box
$machinelearning=$_POST["machinelearning"]; //accessing value from 2nd text field
$blockchain=$_POST['blockchain']; //accessing value from 3rd text field
$internetofthings=$_POST['internetofthings']; //accessing value from 4th text field
$php=$_POST['php'];//accessing value from 5th text field
$sum=$machinelearning+$blockchain+$internetofthings+$php; //total marks
$totalgrades=$sum/4;
$percentage= ($sum / 400) * 100;
if($totalgrades>=0&&$totalgrades<=50)
$grade="Fail";
if($totalgrades>50&&$totalgrades<=70)
$grade="C";
if($totalgrades>70&&$totalgrades<=80)
$grade="B";
if($totalgrades>80&&$totalgrades<=90)
$grade="A";
if($totalgrades>90)
$grade="E";
echo "<br>";
echo "<font size=4><center>Student is:-".$name."</center><br>";
echo "<font size=4><center>Total marks:-".$sum."</center><br>";
echo "<font size=4><center>Percentage is:-".$percentage."%</center>";
echo "<font size=4><center>Grade is:-".$grade."</center>";
}
?>
</form>
</body>
</html>
OUTPUT:
PRACTICAL-5
AIM: Design and develop a dynamic web page using prompt, alert
and confirm box.
<!DOCTYPE html>
<html>
<head>
<title>Practical 3</title>
</head>
<body>
<script>
switch(c){
case 1:
document.write(result);
break;
case 2:
document.write(result);
break;
case 3:
document.write(result);
break;
case 4:
document.write(result);
break;
</script>
</body>
</html>
Output:
PRACTICAL- 6
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if (empty($_POST["name"])) {
$nameErr = "Name is required";
} else {
$name = test_input($_POST["name"]);
// check if name only contains letters and whitespace
if (!preg_match("/^[a-zA-Z-' ]*$/",$name)) {
$nameErr = "Only letters and white space allowed";
}
}
if (empty($_POST["email"])) {
$emailErr = "Email is required";
} else {
$email = test_input($_POST["email"]);
// check if e-mail address is well-formed
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$emailErr = "Invalid email format";
}
}
if (empty($_POST["website"])) {
$website = "";
} else {
$website = test_input($_POST["website"]);
// check if URL address syntax is valid
if (!preg_match("/\b(?:(?:https?|ftp):\/\/|www\.)[-a-z0-9+&@#\/%?=~_|!:,.;]*[-a-z0-
9+&@#\/%=~_|]/i",$website)) {
$websiteErr = "Invalid URL";
}
}
if (empty($_POST["comment"])) {
$comment = "";
} else {
$comment = test_input($_POST["comment"]);
}
if (empty($_POST["gender"])) {
$genderErr = "Gender is required";
} else {
$gender = test_input($_POST["gender"]);
}
}
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
?>
<input type="radio" name="gender" value="other">Other
<span class="error">* <?php echo $genderErr;?></span>
<br><br>
<input type="submit" name="submit" value="Submit">
</form>
<?php
echo "<h2>Your Input:</h2>";
echo $name;
echo "<br>";
echo $email;
echo "<br>";
echo $website;
echo "<br>";
echo $comment;
echo "<br>";
echo $gender;
?>
</body>
</html>
Output:
PRACTICAL-7
AIM: Continue the program no. 4 and apply date and time.
<html>
<body>
<form action="" method="post">
<center>
<table border=0>
<tr>
<td>
Student Name
</td>
<td>
<input type='text' name="name" placeholder="Name of Student">
</td>
</tr>
<tr>
<td>
Marks for Machine Learning
</td>
<td>
<input type='text' name="machinelearning" placeholder="MACHINE LEARNING">
</td>
</tr>
<tr>
<td>
Marks for BlockChain
<td>
<input type='text' name="blockchain" placeholder="BLOCKCHAIN">
</td>
</tr>
<tr>
<td>
Marks for Internet of Things
</td>
<td>
<input type=text name="internetofthings" placeholder="INTERNET OF THINGS">
</td>
</tr>
<tr>
<td>
OUTPUT:
PRACTICAL-8
</tr>
<tr>
<td>
Marks for Open ST using PHP
</td>
<td>
<input type='text' name="php" placeholder="PHP">
</td>
</tr>
</table>
<br>
<br>
<input type='submit' name="submit" value="Result">
</center>
<?php
if(isset($_POST["submit"]))////checking whether the input element is set or not
{
$name=$_POST['name']; //accessing value from 1st text box
$machinelearning=$_POST["machinelearning"]; //accessing value from 2nd text field
$blockchain=$_POST['blockchain']; //accessing value from 3rd text field
$internetofthings=$_POST['internetofthings']; //accessing value from 4th text field
$php=$_POST['php'];//accessing value from 5th text field
$sum=$machinelearning+$blockchain+$internetofthings+$php; //total marks
$totalgrades=$sum/4;
$percentage= ($sum / 400) * 100;
if($totalgrades>=0&&$totalgrades<=50)
$grade="Fail";
if($totalgrades>50&&$totalgrades<=70)
$grade="C";
if($totalgrades>70&&$totalgrades<=80)
$grade="B";
if($totalgrades>80&&$totalgrades<=90)
$grade="A";
if($totalgrades>90)
$grade="E";
echo "<br>";
echo "<font size=4><center>Student is:-".$name."</center><br>";
echo "<font size=4><center>Total marks:-".$sum."</center><br>";
echo "<font size=4><center>Percentage is:-".$percentage."%</center>";
echo "<font size=4><center>Grade is:-".$grade."</center>";
echo "<font size=4><center>".$date = date('m/d/Y h:i:s a', time())."</center>";
}
?>
</form>
</body>
</html
OUTPUT:
PRACTICAL-9
OUTPUT:
PRACTICAL-10
I. Name of author.
II. Title of Book.
III. Publisher.
IV. Volume.
<?php
if(isset($_POST['submit'])){
$author = $_POST['author'];
$title = $_POST['title'];
$publisher = $_POST['publisher'];
$volume = $_POST['volume'];
$sql = "INSERT INTO books SET author = '$author', title = '$title', publisher =
'$publisher', volume = '$volume'";
if(mysqli_query($connect, $sql)){
?>
HTML Code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<link rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css"
integrity="sha384-
Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/
dAiS6JXm" crossorigin="anonymous">
<title>Registeration Form</title>
</head>
<body>
<div class="jumbotronjumbotron-fluid">
<div class="container">
</div>
</div>
<div class="container">
</div>
</div>
</div>
</div>
</div>
</form>
</div>
</body>
</html>
Output:
PRACTICAL-11
AIM: Write a PHP program to read the employee detail using form
component.
<!DOCTYPE html>
<html lang="en">
<head>
<title>Employee Details</title>
</head>
<div class="container">
</div>
</div>
<div class="container">
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<option value="BCA">BCA</option>
<option value="MCA">MCA</option>
</select>
</div>
<option value="Principal">Principal</option>
<option value="Professor">Professor</option>
<option value="Clerk">Clerk</option>
</select>
</div>
<option value="Male">Male</option>
<option value="Female">Female</option>
</select>
</div>
</form>
</div>
</body>
</html>
Output:
PRACTICAL-12
OUTPUT: