WBP
WBP
2. Write JavaScript to validate the following fields of the Registration page. 23-09-2022
A. First Name (Name should contains alphabets and the length should not
be less than 6 characters).
B. Password (Password should not be less than 6 characters length).
C. E-mail id (should not contain any invalid and must follow the
standard pattern [email protected])
D. Mobile Number (Phone number should contain 10 digits only).
E. Last Name and Address (should not be Empty).
3. Write and explain the installation steps and method of PHP using screen shots. 30-09-2022
PHP can be installed using two ways:
1) Using WAMP
2) Using XAMP
4. Write a script to echo the following to the browser, using the variable you created: 30-09-2022
“What goes around, comes around.”
5. Write a PHP Script to calculate the area and circumference of circle. 07-10-2022
6. Write a script to reproduce the output below. Manipulate only one variable using 07-10-2022
simple and using no simple arithmetic operators (assignment operator s) to
produce the values given in the statements. In the script each statement ends with
"Value is now $variable."
Value is now 8.
Add 2. Value is now 10.
Subtract 4. Value is now 6.
Multiply by 5. Value is now 30.
Divide by 3. Value is now 10.
Increment value by one. Value is now 11.
Decrement value by one. Value is now 10.
7. Write a script using one variable “$whatisit” to print the following to the browser. 07-10-2022
Your echo statements may include no words except “Value is”.
Value is string.
Value is double.
Value is boolean.
Value is integer.
Value is NULL.
8. Write a PHP scripts to differentiate the print and echo command 14-10-2022
12. Write a PHP script using nested for loop that creates a chess board 21-10-2022
13. Write a PHP program to find three numbers from an array such that the sum of 21-10-2022
three consecutive numbers equal to zero.
14. Create an index array with value red, green, orange, blue, pink, white and black, 28-10-2022
Count the total array and display all values of array using for loop.
15. Create an Associative array with value fruits, veggie, dry-fruits and Count the 28-10-2022
total array and display all values of array using for each loop.
16. Create an Multidimensional Array and Display the array with index and values 28-10-2022
using <pre> tag.
17. Write a PHP script to sort the following associative array : 28-10-2022
array("Sophia"=>"31","Jacob"=>"41","William"=>"39","Ramesh"=>"40") in
a) ascending order sort by value
b) ascending order sort by Key
c) descending order sorting by Value
d) descending order sorting by Key
18. WAP to swap two values (call by reference) using function 04-11-2022
19. WAP to create a PHP form according to the given format 04-11-2022
20. Design a form given below with validation and error message in PHP 11-11-2022
23. Write a program to store the current date and time in a cookie and display the last 25-11-2022
visited date and time on the web page
24. Write a program to store page views counting session to increment the count on 25-11-2022
each refresh and to show the count on the page
25. Write and explain the steps to create a database, table, select query using 2-12-2022
PhpMyadmin.
A. HOME PAGE: The static home page must contain three frames.
B. LOGIN PAGE
C. CATOLOGUE PAGE: The catalogue page should contain the details of all the
books available in the web site in a table.
D. REGISTRATION PAGE
Code:
Q.2 Write JavaScript to validate the following fields of the Registration page.
A. First Name (Name should contains alphabets and the length should not be less than
6 characters).
B. Password (Password should not be less than 6 characters length).
C. E-mail id (should not contain any invalid and must follow the standard pattern
[email protected])
D. Mobile Number (Phone number should contain 10 digits only).
E. Last Name and Address (should not be Empty).
Code:
<html>
<head>
<title>Registration Form</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<style type="text/css">
.col-lg-9 {
float: right;
margin-top: -80px;
margin-right: 500px;
color: white;
}
.container {
background-color: #ac2727;
min-height: 300px;
.img-pos {
z-index: 999;
position: relative;
left: 70px;
top: 50px;
.container2 {
margin-top: 40px;
text-align: center;
max-width: 400px;
position: relative;
left: 700px;
</style>
</head>
<body>
<div class="container">
<div class="row">
<div class="col-lg-3">
</div>
<div class="col-lg-9">
<h3>Approved by AICTE</h3>
<h3>Rated as Category 'A+' by SFRC & 'A' by JAC Govt. of NCT of Delhi</h3>
</div>
</div>
</div>
<div class="container2">
<fieldset>
<legend>Contact Details</legend>
<label for="password">Password:</label>
<label for="email">Email:</label>
<input type="email" id="email" name="email"><br><br>
<h2 id="result"></h2><br><br>
<label for="address">Address:</label>
</fieldset>
</form>
</div>
<script type="text/javascript">
return email.match(
/^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]
{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
);
};
$result.text('');
if (validateEmail(email)) {
$result.css('color', 'green');
} else {
$result.css('color', 'red');
return false;
$('#email').on('input', validate);
function validateNumber(e) {
return pattern.test(e.key)
</script>
</body>
</html>
Output:
Q.3 Write and explain the installation steps and method of PHP using screen shots.
Ans-
1)Using WAMP
Step 1:To download the WAMP Server, visit the "wamp server website in your web browser.
Click on the "WAMP SERVER 64 BITS (X64).
Step 3: Double-click the downloaded file to launch the WAMP installer. "Select Setup
Language" window will appear on the screen and then choose your preferred language.
Step 4: Under the "License Agreement", click on the "I accept the agreement" radio button and
then click on the "Next" button then Click on the "Next" button.
Step 5: Choose a location (folder) to install the WAMP server and click on the "Next" button.
Step 6: Select the start menu folder. "Ready to Install" window will appear on the screen and
then, click on the "Next" button.
Step 7: Now, select the default browser and default text editor for the wamp server. Click on the
"Finish" button.
2) Using XAMP
Step 1:search xampp server or visit apachefriends.org.
Step 2: click on download according to the your platform and Once the software bundle has been
downloaded, you can start the installation by double clicking on the file.
Step 3:setup the wizard
Step 4: Under ‘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. After making your choice,
click ‘Next’.
Code:
<?php
echo $s1;
?>
Output:
Q.5 Write a PHP Script to calculate the area and circumference of circle.
Code:
<?php
$r = 5;
echo "<br>";
?>
Output:
Q.6 Write a script to reproduce the output below. Manipulate only one variable using
simple and using no simple arithmetic operators (assignment operator s) to produce the
values given in the statements. In the script each statement ends with "Value is now
$variable."
Value is now 8.
Add 2. Value is now 10.
Subtract 4. Value is now 6.
Multiply by 5. Value is now 30.
Divide by 3. Value is now 10.
Increment value by one. Value is now 11.
Decrement value by one. Value is now 10.
Code:
<?php
$x=8;
$x += 2;
$x -= 4;
$x *= 5;
$x /= 3;
$x = ++$x;
$x = --$x;
?>
Output:
Q.7 Write a script using one variable “$whatisit” to print the following to the browser.
Your echo statements may include no words except “Value is”.
Value is string.
Value is double.
Value is boolean.
Value is integer.
Value is NULL.
Code:
<?php
$num = "whatisit";
var_dump($num);
settype($num, "string");
echo "<br>";
settype($num, "double");
echo "<br>";
settype($num, "integer");
echo "<br>";
settype($num, "boolean");
?>
Output:
Q.8 Write a PHP scripts to differentiate the print and echo command.
Code:
<?php
?>
Output:
Q.9 Write a script to display implicit casting and explicit casting.
Code:
<?php
$x = 2;
$y = 4;
Output:
Q.10 Write a PHP scripts to differentiate the $ and $$.
Code:
<?php
$x="abc";
$$x=200;
echo$x,"<br>";
echo$abc;
?>
Output:
Q.11 Write a program to calculate Electricity bill in PHP Conditions: For first 50 units –
Rs. 3.50/unit For next 100 units – Rs. 4.00/unit For next 100 units – Rs. 5.20/unit For units
above 250 – Rs. 6.50/unit Hint:-You can use conditional statements.
Code:
<html>
<head>
<title>Electricity Bill</title>
</head>
<body>
<center>
</form>
</center>
<?php
if(isset($_POST['submit'])){
$unit = $_POST['unit'];
echo "<center><h2>".$bill."</h2></center>";
echo "<center><h2>".$bill."</h2></center>";
}else{
echo "<center><h2>".$bill."</h2></center>";
?>
</body>
</html>
Output:
Q.12 Write a PHP script using nested for loop that creates a chess board
Code:
Q.13 Write a PHP program to find three numbers from an array such that the sum of three
consecutive numbers equal to zero
Code:
Q.14 Create an index array with value red, green, orange, blue, pink, white and black,
Count the total array and display all values of array using for loop.
Code:
<?php
$color=array("red","green","orange", "blue", "pink", "white","black");
$count=0;
for($i=0;$i<=6;$i++)
{
$count=$i+1;
echo "<br>" .$color[$i];
}
echo "The total number of elements in array are:" .$count;
?>
Output:
Q. 15 Create an Associative array with value fruits, veggie, dry-fruits and Count the total
array and display all values of array using for each loop.
Code:
<?php
$arr=array("fruits"=>"1","veggie"=>2,"dry-fruits"=>"3");
echo "Size of Array is:".sizeof($arr);
echo "<br>";
foreach($arr as $key=> $value)
{
echo "Key=" . $key .",Value=" .$value;
echo "<br>";
}
?>
Output:
Q.16 Create an Multidimensional Array and Display the array with index and values using
pre tag.
Code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<?php
/* Multidimensional 2D array for 4 books and each book having a different array containing
book name, cost and type. */
$books = array(
array("Fiction ", "Action and Adventure ", 800),
array("Fiction ", "Anthology ", 1000),
array("Non- Fiction ", "Biography ", 600),
array("Non- Fiction ", "Cook Book ", 900)
);
echo '<pre>',print_r($books,1),'</pre>';
echo "<br>";
?>
</body>
</html>
Output:
Q.17 Write a PHP script to sort the following associative array :
array("Sophia"=>"31","Jacob"=>"41","William"=>"39","Ramesh"=>"40") in
Code:
<?php
$array2=array("Sophia"=>"31","Jacob"=>"41","William"=>"39","Ramesh"=>"40");
asort($array2);
foreach($array2 as $y=>$y_value)
$array3=array("Sophia"=>"31","Jacob"=>"41","William"=>"39","Ramesh"=>"40");
ksort($array3);
foreach($array3 as $y=>$y_value)
$age=array("Sophia"=>"31","Jacob"=>"41","William"=>"39","Ramesh"=>"40");
arsort($age);
foreach($age as $y=>$y_value)
$array4=array("Sophia"=>"31","Jacob"=>"41","William"=>"39","Ramesh"=>"40");
krsort($array4);
foreach($array4 as $y=>$y_value)
?>
Output:
Q.18 WAP to swap two values (call by reference).
Code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<html>
<body>
<?php
function f1(&$a) // here $a is a formal parameter
{
$a.="Year";
}
$b="Happy new ";
f1($b);
echo $b;
?>
</body>
</html>
</body>
</html>
Output:
Q.19 WAP to create a php form according to the given format
Code:
<html>
<head><title>Login Form</title></head>
<body>
<form method="POST" action="eg.php">
<p>PHP HTML Form Input Example</p>
Output:
Q.20 Design a form given below with validation and error message in PHP
Code:
Q.21 Write a PHP Script to demonstrate the file handling in
php(fopen,fclose,fread,fwrite,file length)
Code:
<?php
echo fread($myfile,filesize("text.txt"));
$filesize = filesize("text.txt");
fwrite($myfile, $txt);
echo fread($myfile,filesize("text.txt"));
echo $filesize;
fclose($myfile);
?>
Output:
Q.22 Write a program to upload a file.
Code:
<html>
<head>
<title>File Upload</title>
</head>
<body>
<center>
<h1>File upload</h1>
</form>
</center>
</body>
</html>
<?php
$target_dir = "uploads/";
$uploadOk = 1;
if (isset($_POST["submit"])) {
$check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
$uploadOk = 1;
} else {
$uploadOk = 0;
?>
Output:
Q.23 Write a program to store the current date and time in a cookie and display the last
visited date and time on the web page.
Code:
<html>
<body >
<br>
<?php
$inTwoMonths = 60 * 60 * 24 * 60 + time();
if(isset($_COOKIE['lastVisit']))
$visit = $_COOKIE['lastVisit'];
else
?>
</body>
</html>
Output:
24. Write a program to store page views counting session to increment the count on each
refresh and to show the count on the page.
Code:
<?php
session_start();
if(isset($_SESSION['count']))
$_SESSION['count'] = $_SESSION['count']+1;
else
$_SESSION['count']=1;
echo"views = ".$_SESSION['count'];
?>
Output:
Q.25 Write and explain the steps to create a database, table, select query using
PhpMyadmin.
Create database
creating a new table specify your table name .And click create.
Q.26 Write a PHP program to
create a connection
create a database and
create a table
Code:
<?php
$servername = "localhost";
$username = "root";
$password = "";
if ($conn->connect_error) {
} else
} else {
$dbname="testdb";
email VARCHAR(50)
)";
} else {
$conn->close();
?>
Output:
Q.28 Write a PHP program to insert record into a table
Code:
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "test";
if ($conn->connect_error) {
if(mysqli_query($conn,$sql))
?>
Output:
Q.29 Write a PHP program to select data and show into table format
Code:
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "test";
if ($conn->connect_error) {
echo"<table border='3'>";
echo"<tr><td>Name</td><td>Email</td></tr>";
echo"<tr><td>".$row['name']."</td><td>".$row['email']."</td></tr>";
echo"</table>";
?>
Output:
Q.30 Create a student Registration in PHP and Save and Display the student Records.
Code:
<html>
<head>
<script src="https://cdn.jsdelivr.net/npm/@popperjs/[email protected]/dist/umd/popper.min.js"
integrity="sha384-oBqDVmMz9ATKxIep9tiCxS/Z9fNfEXiDAYTujMAeBAsjFuCZSmKbSSU
nQlmh/jp3" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js"
integrity="sha384-
mQ93GR66B00ZXjt0YO5KlohRA5SY2XofN4zfuZxLkoj1gXtW8ANNCe9d5Y3eG5eD"
crossorigin="anonymous"></script>
<style type="text/css">
body{
background-color: #800000;
color: white;
.form-control{
margin-left: 50px;
</style>
</head>
<body>
<div class="container">
<label for="name">Name:</label>
<input type="text" name="name" required><br><br>
<label for="dob">D.O.B:</label>
<label for="sex">Sex:</label>
<label for="email">Email:</label>
<label for="address">Address:</label>
<label for="school">School:</label>
</select><br><br>
<label for="department">Department:</label>
</select><br><br>
<label for="course">Courses:</label>
<option value="BCA">BCA</option>
<option value="BBA">BBA</option>
<option value="BCom">B.Com</option>
</select><br><br>
</form>
</div>
</body>
</html>
Output: