Professional Documents
Culture Documents
Lab Assignment
echo "This", " string", " was", " made", " with multiple parameters.";
print("Welcome to PHP"."<br>");
?>
OUTPUT:
This string was made with multiple parameters. Welcome to PHP Programming!!!!
Welcome to PHP
Hello World
2. Write a PHP script to demonstrate arithmetic operators, comparison operator, and logical operator.
<?php
$x=100;
$y=60;
?>
Output:
<?php
$a = 80;
$b = 50;
$c = "80";
?>
Output:
bool(true)
bool(true)
bool(true)
bool(false)
bool(true)
bool(false)
bool(true)
bool(false)
bool(true)
<?php
$x = 50;
$y = 30;
if ($x == 50 or $y == 20)
if ($x == 50 || $y == 20)
?>
Output:
and Success
or Success
xor Success
&& Success
|| Success
! Success
<?php
$num = 0;
$n1 = 0;
$n2 = 1;
echo "\n";
$n1 = $n2;
$n2 = $n3;
$num = $num + 1;
?>
OUTPUT:
0 1 1 2 3 5 8 13 21 34 55 89
<?php
echo $x+$y;
$var="add";
$var(10,20);
?>
Output:
30
<?php
$str1="PHP";
$str2="Programming";
$l1=strlen($str1);
$l2=strlen($str2);
$add=$str1+$str2;
$ord=ord($add);
$chr=chr($ord);
?>
<?php
$season=array("summer","winter","spring","autumn");
echo count($season);
sort($season);
foreach($season as $s)
}
reverseseason=array_reverse($season);
foreach($reverseseason as $s)
$key=array_search("spring”, $season);
echo $key;
?>
7. Create student registration form using text box, check box, radio button, select, submit button. And
display user inserted value in new PHP page.
<html>
<head>
<title>Registration</title>
<style>
.main
width:30%;
margin:2em auto;
padding:1em;
.main input[type="submit"]
width:95%;
padding:.5em;
margin:.5em;
.main input[type="password"]
width:95%;
padding:.5em;
margin:.5em;
width:45%;
padding:.5em;
margin:.5em;
</style>
</head>
<body>
<div class="main">
<h2>Student Registration</h2>
<hr>
Gender<br>
<hr>
Hobbies<br>
<hr>
</form>
</div>
</body>
</html>
Welcome Page Script:
<?php
if(isset($_POST['submit']))
$fn=$_POST['fname'];
$ln=$_POST['lname'];
$em=$_POST['email'];
$mob=$_POST['mobile'];
$city=$_POST['city'];
$gender=$_POST['gender'];
$hobbies=$_POST['hobby'];
$pass=$_POST['pass'];
echo "<h3>Hobbies</h3>";
$i=0;
while($i<sizeof($hobbies))
echo $hobbies[$i]."<br>";
$i++;
?>
8. Write two different PHP script to demonstrate passing variables through a URL.
<?php
$fname="Sarjil";
$lname="Shaikh";
?>
<a href="retrive.php?First_name=<?php echo $fname;?>&last_name=<?php echo $lname;?>">
</a>
<?php
?>
<html>
<head>
<title>Cookie Demo</title>
</head>
<body>
<form method="post">
</form>
</body>
</html>
<?php
if(isset($_POST['submit']))
$name=$_POST['fname'];
setcookie('myname',$name,time()+100,"/","",0);
if(!isset($_COOKIE['myname']))
?>
function checkNumber($num) {
if($num>=1) {
return true;
try {
checkNumber(5);
echo 'If you see this text, the passed value is less than 1';
?>
Output:
11. Write a PHP script to connect MySQL server from your website.
<?php
$servername = "localhost";
$username = "yourusername";
$password = "yourpassword “;
if ($conn->connect_error) {
?>
12. Write a program to read customer information like cust_no, cust_name, Item_purchase, and mob_no,
from customer table and display all these information in table format on output screen.
13. Write a program to read employee information like emp_no, emp_name, designation and salary from
EMP table and display all this information using table format.
Index.Php
<?php
$stringData = "
<?php include('config.php');?>
<?php include('header.php');?>
<?php include('sidebarmenu.php');?>
<p>
<ul>
</ul>
</p>
<?php include('footer.php');?>
";
fwrite($fh, $stringData);
?>
Output : Filename.Html
Automatically This index.php file run to create a filename.html or filename.php genrated dynamically.
<?php include('config.php');?>
<?php include('header.php');?>
<?php include('sidebarmenu.php');?>
<p>
<ul>
</p>
<?php include('footer.php');?>
PHP script to dynamically generate simple links to the files present in current directory
<?php
$dir_open = opendir('.');
echo $link;
closedir($dir_open);
?>
header("Content-type: text/plain");
print "how to make a dynamic web pages using php & mysql\n";
print $result;
?>
15. Write a program for JSP scriptlet tag that prints the user name
File: index.html
<html>
<body>
<form action="welcome.jsp">
</form>
</body>
</html>
File: welcome.jsp
<html>
<body>
<%
String name=request.getParameter("uname");
out.print("welcome "+name);
%>
</form>
</body>
</html>
16. Write a program for JSP expression tag that prints current time
To display the current time, we have used the getTime() method of Calendar class. The getTime() is an instance
method of Calendar class, so we have called it after getting the instance of Calendar class by the getInstance()
method.
index.jsp
<html>
<body>
</body>
</html>
17. Write a program for JSP declaration tag that declares method
<html>
<body>
<%!
return n*n*n*;
%>
</body>
</html>
18. Write a program for JSP for request and response implicit object
index.html
<form action="welcome.jsp">
welcome.jsp
<%
String name=request.getParameter("uname");
out.print("welcome "+name);
%>
index.html
<form action="welcome.jsp">
</form>
welcome.jsp
<%
response.sendRedirect("http://www.google.com");
%>
index.html
<html>
<body>
<form action="welcome.jsp">
</form>
</body>
</html>
welcome.jsp
<html>
<body>
<%
String name=request.getParameter("uname");
out.print("Welcome "+name);
session.setAttribute("user",name);
</body>
</html>
second.jsp
<html>
<body>
<%
String name=(String)session.getAttribute("user");
out.print("Hello "+name);
%>
</body>
</html>
index.jsp
<form action="process.jsp">
</form>
process.jsp
<%
String num1=request.getParameter("n1");
String num2=request.getParameter("n2");
int a=Integer.parseInt(num1);
int b=Integer.parseInt(num2);
int c=a/b;
%>
error.jsp
21. Write a program for JSP for Simple example of java bean class.
package mypack;
public Employee(){}
package mypack;
System.out.println(e.getName());
}}
1. <jsp:include> Action
<html>
<head>
</head>
<body>
</body>
</html>
2. <jsp:forward> Action
<html>
<head>
<body>
</body>
</html>
html>
<head>
</head>
<body>
<jsp:forward page="second.jsp">
</jsp:forward>
</body>
</html>
4. <jsp:useBean>Action
square.java
Package demotest;
{return n*n;} }
example.jsp
<html>
<title>usebean</title>
<body>
<%
int m=obj.square(3);
out.print("square of 3 is "+m);
%>
</body>
</html>
TestBean.java
package demotest;
import java.io.Serializable;
return msg;
this.message = message;
GetSet.jsp
pageEncoding="ISO-8859-1"%>
<html>
<head>
</head>
<body>
</body>
</html>
<html>
</head>
<body>
<jsp:element name="XMLelement">
<jsp:attribute name="XMLattribute">
</jsp:attribute>
<jsp:body> My XML</jsp:body>
</jsp:element>
</body>
</html>
7. <jsp:text>
<html>
<head>
<title>Template</title>
</head>
<body>
</body>
</html>
8. <jsp: output>
<html>
<head>
<title>Output Actions</title>
</head>
<body>
</body>
</html>