WPPPPPPP
WPPPPPPP
WPPPPPPP
Output :
<?php
for($i=1;$i<=5;$i++)
{
for($j=1;$j<=$i;$j++)
{
echo "$j";
echo " ";
}
echo"<br>";
}
?>
Output :
Output :
b) Write a HTML code that takes name and email as input and display the entered
details using $_GET array.
get.html
<!DOCTYPE html>
<html>
<head>
<title>Get Form</title>
</head>
<body>
<h1>Get Form</h1>
<form action="get.php" method="GET">
Name : <input type="text" name="name"/><br><br>
Email : <input type="email" name="email"/><br><br>
<input type="submit"/>
</form>
</body>
</html>
get.php
<!DOCTYPE html>
<html>
<head>
<title>PHP Form</title>
</head>
<body>
<p>Welcome <?php echo $_GET['name']; ?></p>
<p>Email is <?php echo $_GET['email']; ?></p>
</body>
</html>
Output :
<!DOCTYPE>
<html>
<head>
<title>Hide and Show</title>
<script src="jquery.js"></script>
<script>
$(document).ready(function(){
$(".showbtn").click(function(){
$("p").show();
});
$(".hidebtn").click(function(){
$("p").hide();
});
});
</script>
</head>
<body>
<p>This text is shown.</p>
<br>
<button class="showbtn">Show</button>
<button class="hidebtn">Hide</button>
</body>
</html>
Output :
b) Write a HTML code that takes name and email as input and display the entered
details using $_POST array.
post.html
<!DOCTYPE html>
<html>
<head>
<title>Post Form</title>
</head>
<body>
<h1>Post Form</h1>
<form action="post.php" method="POST">
Name : <input type="text" name="name"/><br><br>
Email : <input type="email" name="email"/><br><br>
<input type="submit"/>
</form>
</body>
</html>
post.php
<!DOCTYPE html>
<html>
<head>
<title>Post PHP</title>
</head>
<body>
<p>Welcome <?php echo $_POST['name']; ?></p>
<p>Your email is <?php echo $_POST['email']; ?></p>
</body>
</html>
Output :
<!DOCTYPE html>
<html>
<head>
<title>Clock</title>
<meta http-equiv="refresh" content="1"/>
</head>
<body>
<h1><?php echo date("h : i : s A"); ?></h1>
</body>
</html>
Output :
b) Write a PHP script that accepts filename, extension, text content and writes into
file.
<!DOCTYPE html>
<html>
<head>
<title>File extentions</title>
</head>
<body>
<form method="post">
<p>File name : <input type="text" name="file"/>
<p>Extention : </p>
<select name="ext">
<option value="txt">txt</option>
<option value="doc">doc</option>
<option value="pdf">pdf</option>
<option value="docx">docx</option>
<option value="odt">odt</option>
</select>
<br><br>
<textarea name="cont"></textarea><br><br>
<input type="submit" value="submit" name="submit"\>
</form>
</body>
</html>
<?php
if(isset($_POST['submit']))
{
$filename = $_POST['file'];
$extention = $_POST['ext'];
$content = $_POST['cont'];
?>
Output :
<?php
$arr1 = array(45,23,98,32,44,12,45,23,22,23,86,44);
$arr2 = array(56,75,23,64,23,44,32,64,21,54,23,64);
echo "Array 1 : ";
echo "<br>";
foreach($arr1 as $val){
echo("$val ");
}
echo "<br><br>";
echo "Array 2 : ";
echo "<br>";
$s1=count($arr2);
for($i=0;$i<$s1;$i++){
echo($arr2[$i]);
echo " ";
}
sort($arr1);
sort($arr2);
echo "<br><br>";
echo "Sorted array 1 : ";
echo "<br>";
foreach($arr1 as $val){
echo("$val ");
}
echo "<br><br>";
echo "Sorted array 2 : ";
echo "<br>";
foreach($arr2 as $val){
echo("$val ");
}
$res = array_unique(array_intersect($arr1,$arr2));
echo "<br><br>";
echo "Common elements : ";
echo "<br>";
foreach($res as $val){
echo("$val ");
}
$arr_unique1 = array_unique($arr1);
$arr_unique2 = array_unique($arr2);
echo "<br><br>";
echo "Unique array 1 : ";
echo "<br>";
foreach($arr_unique1 as $val){
echo("$val ");
}
echo "<br><br>";
echo "Unique array 2 : ";
echo "<br>";
foreach($arr_unique2 as $val){
echo("$val ");
}
?>
Output :
<!DOCTYPE html>
<html>
<head>
<title>Temperature Table</title>
<style>
table, th, td {
border: 1px solid black;
border-collapse: collapse;
padding: 10px;
}
</style>
</head>
<body>
<h1>Temperature Table</h1>
<table>
<tr>
<th colspan="2">Farenheit to Celcius</th>
<th colspan="2">Celcius to Farenheit</th>
</tr>
<tr>
<th>Farenheit</th>
<th>Celcius</th>
<th>Celcius</th>
<th>Farenheit</th>
</tr>
<?php for($i=32;$i<=42;$i++) { ?>
<tr>
<td><?php echo($i); ?></td>
<td><?php echo ((($i - 32)*5)/9); ?></td>
<td><?php echo($i); ?></td>
<td><?php echo (((($i)*9)/5)+32); ?></td>
</tr>
<?php } ?>
</table>
</body>
</html>
Output :
<?php
echo "-------------------";
echo "-------------------";
echo "<br><br>";
echo file_get_contents("new_file.txt");
echo "<br><br>";
echo "-------------------";
echo "-------------------";
echo "<br><br>";
echo file_get_contents("new_file1.txt");
echo "<br><br>";
?>
Output :
b) Write a HTML code that takes name and email as input and display the entered
details using $_POST array.
post.html
<!DOCTYPE html>
<html>
<head>
<title>Post Form</title>
</head>
<body>
<h1>Post Form</h1>
<form action="post.php" method="POST">
Name : <input type="text" name="name"/><br><br>
Email : <input type="email" name="email"/><br><br>
<input type="submit"/>
</form>
</body>
</html>
post.php
<!DOCTYPE html>
<html>
<head>
<title>Post PHP</title>
</head>
<body>
<p>Welcome <?php echo $_POST['name']; ?></p>
<p>Your email is <?php echo $_POST['email']; ?></p>
</body>
</html>
Output :
file_display.html
<!DOCTYPE html>
<html>
<head>
<title>File Manipulation</title>
</head>
<body>
<form action="file_display.php" method="POST">
<p>Enter text : </p>
<textarea name="text"></textarea>
<br><br>
<input type="submit" name="submit" value="submit"\>
</form>
</body>
</html>
file_display.php
<?php
if(isset($_POST['submit'])){
$cont = $_POST['text'];
echo file_get_contents("text_file.txt");
}
?>
Output :
b) Write a HTML code that takes name and email as input and display the entered
details using $_GET array.
get.html
<!DOCTYPE html>
<html>
<head>
<title>Get Form</title>
</head>
<body>
<h1>Get Form</h1>
<form action="get.php" method="GET">
Name : <input type="text" name="name"/><br><br>
Email : <input type="email" name="email"/><br><br>
<input type="submit"/>
</form>
</body>
</html>
get.php
<!DOCTYPE html>
<html>
<head>
<title>PHP Form</title>
</head>
<body>
<p>Welcome <?php echo $_GET['name']; ?></p>
<p>Email is <?php echo $_GET['email']; ?></p>
</body>
</html>
Output :
8. Execute the following:
a)Write a PHP script to sort and display the array in Ascending & descending order.
<?php
$arr = array(34,76,23,12,76,32,11,54,34,76,43,23);
sort($arr);
echo "<br><br>";
echo "Descending order : ";
echo "<br>";
$len=count($arr);
for($i=$len-1;$i>=0;$i--){
echo "$arr[$i]";
echo " ";
}
?>
Output :
b) Write a PHP program to connect to a database and retrieve data from a Student
table. Student table consists of Student Id, Student Name, USN, Branch, City, CGPA.
Show the details in a neat format, Insert Data and show the entered Data, Order Data
based on CGPA, Delete the rows with CGPA less than 7.75. Update the city as
NMAMIT Nitte
<?php
$servername = "172.16.2.3";
$database = "student";
$username = "student";
$password = "student";
if(!$conn){
echo "Connection failed! " . $conn->connect_error;
}
echo "<br><br>";
echo "Display table";
echo "<br>";
$sql3 = mysqli_query($conn, "Select * from student3");
while($data = mysqli_fetch_array($sql3)){
echo "<br>";
echo $data["Student_ID"]." "."|"." ";
echo $data["Student_Name"]." "."|"." ";
echo $data["USN"]." "."|"." ";
echo $data["Branch"]." "."|"." ";
echo $data["City"]." "."|"." ";
echo $data["CGPA"]." "."|"." ";
}
echo "<br><br>";
echo "Ordered by CGPA";
echo "<br>";
$sql4 = mysqli_query($conn, "Select * from student3 order by CGPA");
while($data = mysqli_fetch_array($sql4)){
echo "<br>";
echo $data["Student_ID"]." "."|"." ";
echo $data["Student_Name"]." "."|"." ";
echo $data["USN"]." "."|"." ";
echo $data["Branch"]." "."|"." ";
echo $data["City"]." "."|"." ";
echo $data["CGPA"]." "."|"." ";
}
echo "<br><br>";
echo "Deleting rows with cgpa below 7.75";
echo "<br>";
$sql5 = "Delete from student3 where CGPA<7.75";
if(mysqli_query($conn,$sql5)){
echo "Rows deleted";
} else {
echo "Error";
}
echo "<br><br>";
echo "Display table";
echo "<br>";
$sql7 = mysqli_query($conn, "Select * from student3");
while($data = mysqli_fetch_array($sql7)){
echo "<br>";
echo $data["Student_ID"]." "."|"." ";
echo $data["Student_Name"]." "."|"." ";
echo $data["USN"]." "."|"." ";
echo $data["Branch"]." "."|"." ";
echo $data["City"]." "."|"." ";
echo $data["CGPA"]." "."|"." ";
}
echo "<br><br>";
echo "Updating City to NMAMIT Nitte";
echo "<br>";
$sql6 = "Update student3 set City='NMAMIT Nitte' where Student_ID=103";
if(mysqli_query($conn,$sql6)){
echo "Rows updated";
} else {
echo "Error";
}
echo "<br><br>";
echo "Display table";
echo "<br>";
$sql8 = mysqli_query($conn, "Select * from student3");
while($data = mysqli_fetch_array($sql8)){
echo "<br>";
echo $data["Student_ID"]." "."|"." ";
echo $data["Student_Name"]." "."|"." ";
echo $data["USN"]." "."|"." ";
echo $data["Branch"]." "."|"." ";
echo $data["City"]." "."|"." ";
echo $data["CGPA"]." "."|"." ";
}
?>
Output :
9. Execute the following:
a) Change Text Color of the Elements Using Jquery
<!DOCTYPE>
<html>
<head>
<title>Change Text Color</title>
<script src="jquery.js"></script>
<script>
$(document).ready(function(){
$("p").css("color","cyan")
});
</script>
</head>
<body>
<p>Hello</p>
</body>
</html>
Output :
b) Write a PHP program to connect to a database and retrieve data from a Employee
table. Employee table consists of emp id, emp name, dept, designation, salary, date
of join. Show the details in a neat format, Insert Data and show the entered Data,
Order the Data based on salary.
<?php
$servername = "172.16.2.3";
$database = "student";
$username = "student";
$password = "student";
if(!$conn){
echo "Connection failed! " . $conn->connect_error;
}
if(mysqli_query($conn,$sql1)){
echo "Table created";
} else {
echo "Table not created";
}
echo "<br><br>";
echo "Display table";
echo "<br>";
$sql3 = mysqli_query($conn, "Select * from employee1");
echo "<table>";
echo
"<tr><th>Employee_ID</th><th>Employee_Name</th><th>Department</th><th>Designati
on</th><th>Salary</th><th>Date_of_Join</th></tr>";
while($data = mysqli_fetch_array($sql3)){
echo "<br>";
echo "<tr>";
echo "<td>" . $data['Employee_ID'] . "</td>";
echo "<td>" . $data['Employee_Name'] . "</td>";
echo "<td>" . $data['Department'] . "</td>";
echo "<td>" . $data['Designation'] . "</td>";
echo "<td>" . $data['Salary'] . "</td>";
echo "<td>" . $data['Date_of_Join'] . "</td>";
echo "<tr>";
}
echo "</table>";
echo "<br><br>";
echo "Ordered by Salary";
echo "<br>";
$sql4 = mysqli_query($conn, "Select * from employee1 order by Salary");
echo "<table>";
echo
"<tr><th>Employee_ID</th><th>Employee_Name</th><th>Department</th><th>Designati
on</th><th>Salary</th><th>Date_of_Join</th></tr>";
while($data = mysqli_fetch_array($sql4)){
echo "<br>";
echo "<tr>";
echo "<td>" . $data['Employee_ID'] . "</td>";
echo "<td>" . $data['Employee_Name'] . "</td>";
echo "<td>" . $data['Department'] . "</td>";
echo "<td>" . $data['Designation'] . "</td>";
echo "<td>" . $data['Salary'] . "</td>";
echo "<td>" . $data['Date_of_Join'] . "</td>";
echo "<tr>";
}
echo "</table>";
?>
Output :
10. Execute the following:
a) Write a PHP script that accepts filename, extension, text content and writes into
file.
<!DOCTYPE html>
<html>
<head>
<title>File extentions</title>
</head>
<body>
<form method="post">
<p>File name : <input type="text" name="file"/>
<p>Extention : </p>
<select name="ext">
<option value="txt">txt</option>
<option value="doc">doc</option>
<option value="pdf">pdf</option>
<option value="docx">docx</option>
<option value="odt">odt</option>
</select>
<br><br>
<textarea name="cont"></textarea><br><br>
<input type="submit" value="submit" name="submit"\>
</form>
</body>
</html>
<?php
if(isset($_POST['submit']))
{
$filename = $_POST['file'];
$extention = $_POST['ext'];
$content = $_POST['cont'];
?>
Output :
b) Write a PHP program to connect to a database and retrieve data from a Library
database. The database table consists of Book Id, Book Title, Author name, ISSN,
Price, Edition. Show the details in a neat format, Insert Data and show the entered
Data, Order Data based on Book Title, Delete the rows with Price less than 600.
Update the Author name as Chetan Bhagat.
<?php
$servername = "172.16.2.3";
$database = "student";
$username = "student";
$password = "student";
if(!$conn){
echo "Connection failed! " . $conn->connect_error;
}
echo "Connection established.";
if(mysqli_query($conn,$sql1)){
echo "Table created";
} else {
echo "Table not created";
}
echo "<br><br>";
echo "Ordered by Book_Title";
echo "<br>";
$sql4 = mysqli_query($conn, "Select * from library1 order by Book_Title");
while($data = mysqli_fetch_array($sql4)){
echo "<br>";
echo $data["Book_ID"]." "."|"." ";
echo $data["Book_Title"]." "."|"." ";
echo $data["Author_Name"]." "."|"." ";
echo $data["USN"]." "."|"." ";
echo $data["Price"]." "."|"." ";
echo $data["Edition"]." "."|"." ";
}
echo "<br><br>";
echo "Deleting rows";
echo "<br>";
$sql5 = "Delete from library1 where Price<600";
if(mysqli_query($conn,$sql5)){
echo "Rows deleted";
} else {
echo "Error";
}
echo "<br><br>";
echo "Display table";
echo "<br>";
$sql7 = mysqli_query($conn, "Select * from library1");
while($data = mysqli_fetch_array($sql7)){
echo "<br>";
echo $data["Book_ID"]." "."|"." ";
echo $data["Book_Title"]." "."|"." ";
echo $data["Author_Name"]." "."|"." ";
echo $data["USN"]." "."|"." ";
echo $data["Price"]." "."|"." ";
echo $data["Edition"]." "."|"." ";
}
echo "<br><br>";
echo "Updating rows";
echo "<br>";
$sql6 = "Update library1 set Author_Name='Chetan Bhagat' where Book_ID=101";
if(mysqli_query($conn,$sql6)){
echo "Rows updated";
} else {
echo "Error";
}
echo "<br><br>";
echo "Display table";
echo "<br>";
$sql8 = mysqli_query($conn, "Select * from library1");
while($data = mysqli_fetch_array($sql8)){
echo "<br>";
echo $data["Book_ID"]." "."|"." ";
echo $data["Book_Title"]." "."|"." ";
echo $data["Author_Name"]." "."|"." ";
echo $data["USN"]." "."|"." ";
echo $data["Price"]." "."|"." ";
echo $data["Edition"]." "."|"." ";
}
?>
Output :
11. Execute the following:
a) Creating a simple show and hide effect in jQuery
<!DOCTYPE>
<html>
<head>
<title>Hide and Show</title>
<script src="jquery.js"></script>
<script>
$(document).ready(function(){
$(".showbtn").click(function(){
$("p").show();
});
$(".hidebtn").click(function(){
$("p").hide();
});
});
</script>
</head>
<body>
<p>This text is shown.</p>
<br>
<button class="showbtn">Show</button>
<button class="hidebtn">Hide</button>
</body>
</html>
Output :
b) Write a PHP program to connect to a database and retrieve data from a Car
Database table. Car Database table consists of Reg.No, Reg Owner, Address, Fuel
Type used, Car Model, Price. Show the details in a neat format, Insert Data and show
the entered Data, Order the Data based on Car Price.
<?php
$servername = "172.16.2.3";
$database = "student";
$username = "student";
$password = "student";
if(!$conn){
echo "Connection failed! " . $conn->connect_error;
}
if(mysqli_query($conn,$sql1)){
echo "Table created";
} else {
echo "Table not created";
}
echo "<br><br>";
echo "Display table";
echo "<br>";
$sql3 = mysqli_query($conn, "Select * from car2");
echo "<table>";
echo
"<tr><th>Reg.No</th><th>Reg_Owner</th><th>Address</th><th>Fuel_Type</th><th>Car
_Model</th><th>Price</th></tr>";
while($data = mysqli_fetch_array($sql3)){
echo "<tr>";
echo "<td>" . $data['RegNo'] . "</td>";
echo "<td>" . $data['Reg_Owner'] . "</td>";
echo "<td>" . $data['Address'] . "</td>";
echo "<td>" . $data['Fuel_Type'] . "</td>";
echo "<td>" . $data['Car_Model'] . "</td>";
echo "<td>" . $data['Price'] . "</td>";
echo "<tr>";
}
echo "</table>";
echo "<br><br>";
echo "Ordered by Salary";
echo "<br>";
$sql4 = mysqli_query($conn, "Select * from car2 order by Price");
echo "<table>";
echo
"<tr><th>Reg.No</th><th>Reg_Owner</th><th>Address</th><th>Fuel_Type</th><th>Car
_Model</th><th>Price</th></tr>";
while($data = mysqli_fetch_array($sql4)){
echo "<tr>";
echo "<td>" . $data['RegNo'] . "</td>";
echo "<td>" . $data['Reg_Owner'] . "</td>";
echo "<td>" . $data['Address'] . "</td>";
echo "<td>" . $data['Fuel_Type'] . "</td>";
echo "<td>" . $data['Car_Model'] . "</td>";
echo "<td>" . $data['Price'] . "</td>";
echo "<tr>";
}
echo "</table>";
?>
Output :
12. Execute the following:
a) Write a PHP script to generate the following output
*
**
***
****
*****
<?php
for($i=1;$i<=5;$i++){
for($j=1;$j<=$i;$j++){
echo "* ";
}
echo "<br>";
}
?>
Output :
b) Write a PHP program to connect to a database and retrieve data from a Movie
Database table. Movie Database table consists of Movie Name, Director Name, Actor
Name, Ratings, Role, Language, Genre. Show the details in a neat format, Insert
Data and show the entered Data, Order the Data based on Movie Ratings.
<?php
$servername = "172.16.2.3";
$database = "student";
$username = "student";
$password = "student";
if(!$conn){
echo "Connection failed! " . $conn->connect_error;
}
if(mysqli_query($conn,$sql1)){
echo "Table created";
} else {
echo "Table not created";
}
echo "<br><br>";
echo "Display table";
echo "<br>";
$sql3 = mysqli_query($conn, "Select * from movie1");
echo "<table>";
echo
"<tr><th>Movie_Name</th><th>Director_Name</th><th>Actor_Name</th><th>Ratings</t
h><th>Role</th><th>Language</th><th>Genre</th></tr>";
while($data = mysqli_fetch_array($sql3)){
echo "<tr>";
echo "<td>" . $data['Movie_Name'] . "</td>";
echo "<td>" . $data['Director_Name'] . "</td>";
echo "<td>" . $data['Actor_Name'] . "</td>";
echo "<td>" . $data['Ratings'] . "</td>";
echo "<td>" . $data['Role'] . "</td>";
echo "<td>" . $data['Language'] . "</td>";
echo "<td>" . $data['Genre'] . "</td>";
echo "<tr>";
}
echo "</table>";
echo "<br><br>";
echo "Ordered by Salary";
echo "<br>";
$sql4 = mysqli_query($conn, "Select * from movie1 order by Ratings");
echo "<table>";
echo
"<tr><th>Movie_Name</th><th>Director_Name</th><th>Actor_Name</th><th>Ratings</t
h><th>Role</th><th>Language</th><th>Genre</th></tr>";
while($data = mysqli_fetch_array($sql4)){
echo "<tr>";
echo "<td>" . $data['Movie_Name'] . "</td>";
echo "<td>" . $data['Director_Name'] . "</td>";
echo "<td>" . $data['Actor_Name'] . "</td>";
echo "<td>" . $data['Ratings'] . "</td>";
echo "<td>" . $data['Role'] . "</td>";
echo "<td>" . $data['Language'] . "</td>";
echo "<td>" . $data['Genre'] . "</td>";
echo "<tr>";
}
echo "</table>";
?>
Output :