KEMBAR78
Lab Codes and Outputs | PDF | Letter Case | Computer Data
0% found this document useful (0 votes)
66 views83 pages

Lab Codes and Outputs

The document contains examples of using PHP echo and print statements to output text to the browser. It shows how echo can be used to output multiple parameters separated by commas within one statement. It then shows some examples of using print similarly to output text.

Uploaded by

Prasanna Raj
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
66 views83 pages

Lab Codes and Outputs

The document contains examples of using PHP echo and print statements to output text to the browser. It shows how echo can be used to output multiple parameters separated by commas within one statement. It then shows some examples of using print similarly to output text.

Uploaded by

Prasanna Raj
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 83

Ex.No.

1 ECHO AND PRINT STATEMENTS

<html>
<body>
<?php
echo "<h2>PHP is Fun!</h2>";
echo "Hello world!<br>";
echo "I'm about to learn PHP!<br>";
echo "This ", "string ", "was ", "made ", "with multiple parameters.";
print "<h2>PHP is Fun!</h2>";
print "Hello world!<br>";
print "I'm about to learn PHP!";
?>
</body>
</html>
OUTPUT:
Ex.No.1a TEMPERATURE CONVERTOR
temperature.php
<!DOCTYPE html>
<html>
<head>
<title>Temperature Converter</title>
</head>
<body>
<h1>Temperature Converter</h1><br><br>
<h3>Enter the temperature in the box and select its type...</h3>
<form action="<?php echo $_SERVER['PHP_SELF']?>" method="post">
<input type="number" name="temperature">
<input type="radio" name="units" value="C">Celcius
<input type="radio" name="units" value="F">Farenheit <br><br>
<input type="submit" name="submit" value="CONVERT"><br><br>
</form>
<?php
if(isset($_POST['submit']))
{
$temperature=$_POST['temperature'];
$units=$_POST['units'];
if($units=="C")
{
$result=$temperature*9/5+32;
echo "$temperature degree Celcius = " .$result . " degree Farenheit";
}
else
{
$result=($temperature-32)*5/9;
echo "$temperature degree Farenheit = " .$result . " degree Celcius";
}
}
?>
</body>
</html>
OUTPUT:
CELCIUS TO FARENHEIT:

FARENHEIT TO CELCIUS:
Ex.No.1b BIGGEST OF GIVEN THREE NUMBERS
Biggestofthreenumbers.php
<!DOCTYPE html>
<html>
<head>
<title>Biggest Number</title>
</head>
<body>
<h2>Biggest of three numbers</h2>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']">
<br><br>
Enter the first number:
<input type="number" name="num1"><br><br>
Enter the second number:
<input type="number" name="num2"><br><br>
Enter the third number:
<input type="number" name="num3">
<br><br>
<input type="submit" name="submit" value= FIND <br><br><br>
</form>
</body>
</html>
<?php
11
Notes
if(isset($_POST["submit"])){
$num1=$_POST["num1"];
$num2=$_POST["num2"];
$num3=$_POST["num3"];
echo "The given numbers are:."."<br>";
echo $num1."<br>";
echo $num2."<br>";
echo $num3."<br>";

if($num1>$num2 && $num1>$num3)


{
echo "<br>The Biggest number is:\t".$num1;
}
elseif($num2>$num1 && $num2>$num3)
{
echo "<br>The Biggest number is:\t".$num2;
}
else
echo "<br>The Biggest number is:\t".$num3;
}

?>
OUTPUT:
Ex.No.2a STRING FUNTIONS
stringfunctions.php
<!DOCTYPE html>
<html>
<head>
<title>String Functions</title>
</head>
<body>
<h2>String Functions</h2>
<form action="<?php echo $_SERVER['PHP_SELF']?>" method="post">
<input type="radio" name="name" value=1>String Length<br><br>
<input type="radio" name="name" value=2>word_count <br><br>
<input type="radio" name="name" value=3>String reverse <br><br>
<input type="radio" name="name" value=4>String position <br><br>
<input type="radio" name="name" value=5>String replace <br><br>
<input type="radio" name="name" value=6>Capitalize each word <br><br>
<input type="radio" name="name" value=7>Upper case <br><br>
<input type="radio" name="name" value=8>Lower case <br><br>
<input type="radio" name="name" value=9>Repeat String <br><br>
<input type="radio" name="name" value=10>String compare <br><br>
<input type="radio" name="name" value=11>Sub String <br><br>
<input type="submit" name="submit" value="Submit"><br><br>
</form>

<?php
if(isset($_POST['submit']))
{
if (!empty($_POST['name'])) {
$func=$_POST['name'];
if($func==1)
{
echo " The length of the string Welcome to BHC is:" ."<B>".strlen("Welcome to
BHC")."</B>";//will return the length of given string
echo "<br><br>";
}
elseif($func==2){
echo "The number of words in the string Welcome to BHC is:"
."<B>".str_word_count("Welcome to BHC")."</B>";//will return the number of in the string
echo "<br><br>";}
elseif($func==3){
echo "The string TIRUCHIRAPALLI is reversed as:"
."<B>".strrev("TIRUCHIRAPALLI")."</B>";// will return the string starting from the end
echo "<br><br>";}
elseif($func==4){
echo "The position of the word BHC in Welcome to BHC is:" ."<B>".strpos("Welcome
to BHC","BHC")."</B>"; //Strpos() enables searching particular text within a string
echo "<br><br>";}
elseif($func==5){
echo "The string 'world' is replaced with 'Peter' in 'Hello world!' and so----
"."<B>".str_replace("world","Peter","Hello world!")."</B>";//Str_replace() is a built-in function,
basically used for replacing specific text within a string.
echo "<br><br>";}
elseif($func==6){
echo "The upper case of the first alphabet of every word in welcome to the php world is:"
."<B>".ucwords("welcome to the php world")."</B>";//Ucwords() is used to convert first
alphabet of every word into uppercase.
echo "<br><br>";}
elseif($func==7){
echo "The upper case of the string welcome to bhc is:"."<B>" .strtoupper("welcome
to bhc")."</B>";// It will convert all letters of string into uppercase
echo "<br><br>";}
elseif($func==8){
echo "The lower case of the string WELCOME TO BHC is:"."<B>"
.strtolower("WELCOME TO BHC")."</B>"; //Strtolower() is used to convert a string into
lowercase.
echo "<br><br>";}
elseif($func==9){
echo "Repeating the string '$@' 10
times:"."<br><br>"."<B>".str_repeat("$@",10)."</B>";//for repeating a string a specific number
of times.
}
elseif($func==10){
echo "Given strings are 'Bishop' and 'college'";
echo "<br><br>";
echo "Given strings are compared and found not equal, so:"
."<B>".strcmp("Bishop","college")."</B>";//Both the strings are not equal
}
elseif($func==11){
echo "Using substr function to return 10 characters of the string \"Welcome to College\"
is:"."\t"."<B>".substr("Welcome to BHC",0,10);
}
else{}
}}
?>
</body>
</html>
OUTPUT:
String length:

Word count:
String reverse:

String position:
String replace:

Capitalize each word:


Upper case:

Lower case:
Repeat string:

String compare:
Sub string:
Ex.No.2b FILE HANDLING
Filehandling.php
<?php
echo <<<_END
<form action="" method="post">
<H3><B> Choose a File to view </B></H3>
<br><br>
<select name="files">
<option value=1>Select</option>
<option value=2>Student profile</option>
</select>
<br><br>
<input type="submit" name="submit" value="VIEW">
</form>
_END;
if(isset($_POST['submit']))
{
$files=$_POST['files'];
if($files==2)
{
$document=fopen("text4.txt","r");
if($document==null)
{
echo"Cannot open the file";
exit();
}
else
{
$file=file_get_contents("text4.txt");
$line=explode("\n",$file);
}
foreach($line as $newline)
{
echo $newline."<br>";
}
fclose($document);}}
?>

Contents in text4.txt:
S.No : 1
Rollno : 165214101
Name : Anderson
Mark 1 : 80
Mark 2 : 75
Total : 155
OUTPUT:
Ex.No.3a SIMPLE CALCULATOR
calculator.php
<?php
extract($_POST);
if(isset($save))
{
switch($ch)
{
case '+':
$res=$fn+$sn;
break;
case '-':
$res=$fn-$sn;
break;
case '*':
$res=$fn*$sn;
break;
case '/':
$res=$fn/$sn;
break;
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Calculator</title>
</head>
<body >
<h2>Simple Calculator</h2>
<form method="post">
<table border="1" align="left">
<tr>
<th>Enter your First num</th>
<th><input type="number" name="fn" value="<?php echo @$fn;?>"/></th>
</tr>
<tr>
<th>Enter your Second num</th>
<th><input type="number" name="sn" value="<?php echo @$sn;?>"/></th>
</tr>
<tr>
<th>Select Your Choice</th>
<th>
<select name="ch">
<option>select</option>
<option>+</option>
<option>-</option>
<option>*</option>
<option>/</option>
</select>
</th>
</tr>
<tr>
<th colspan="2">
<input type="submit" name="save" value="Calculate"/>
</th>
</tr>
<tr>
<th>Your Result</th>
<th><input type="number" readonly="readonly" disabled="disabled" value="<?php echo
@$res;?>"/></th>
</tr>
</table>
</form>
</body>
</html>
OUTPUT:
ADDITION(+)

SUBTRACTION(-)
MULTIPLICATION(*)

DIVISION(/)
Ex.No.3b CREATING A FORM
form.php
<!DOCTYPE HTML>
<html>
<body>
<form action="welcome_get.php" method="get">
Name: <input type="text" name="name"><br>
E-mail: <input type="text" name="email"><br>
<input type="submit">
</form>
</body>
</html>

welcome_get.php
<html>
<body>
Welcome <?php echo $_GET["name"]; ?><br>
Your email address is: <?php echo $_GET["email"]; ?>
</body>
</html>
OUTPUT:
Ex.No.3c LOGIN FORM
loginform.php
<html>
<body>
<h1> <b>Login form</b></h1>
<br><br>
<form action="" method="POST">
<pre>
User Name <input type="text" name="user"><br>
Password <input type="password" name="pass"><br>
<input type="checkbox" name="remember">Remember me
&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp<input type="submit"
name="submit" value="login">
</pre> </form>
<?php
if(isset($_POST['submit']))
{
$user = $_POST['user'];
$pass = $_POST['pass'];
if($user=="bhc"&& $pass==123)
{
echo "Login successful";
} else {
echo "Wrong Username/Password.";
}}
?>
</body>
</html>
OUTPUT:
Ex.No.4a EMPLOYEE DETAILS
emp.php
<html>
<body>
<h2><B>Employee Details</B></h2><br><br><br>
<form method="POST" action="Display.php ">
<h3> <B>Enter your details</B></h3>
<pre>
Enter your ID Number : <input type=text name="eno"><br>
Enter your Name : <input type=text name="name"><br>
Enter your Designation : <input type=text name="desig"><br>
Enter your Basic Salary : <input type=number name="sal"><br>
<input type=submit value=view>
</pre>
</form>
</body>
</html>

display.php
<!DOCTYPE html>
<html>
<head>
<title>Employee Details</title>
</head>
<body style="background
-color:lightblue;">
<h2><B>Employee Details</B></h2>
<?php
$number=$_POST['eno'];
$name=$_POST['name'];
$desig=$_POST['desig'];
$bsal=$_POST['sal'];
$pf=$bsal*.02;
$da=$bsal*.06;
$hra=$bsal*.045;
$it=$bsal*.01;
$netsal=$bsal+$da+$hra
-$pf-$it;
echo "<B>Details of ".$name."</B><br><br><br>";
?>
<table border="1" align="left">
<tr>
<th>ID</th>
<th><?php echo $number;?></th>
</tr>
<tr>
<th>Designation</th>
<th><?php echo $desig;?></th>
</tr>
<tr>
<th>Basic Salary</th>
<th><?php echo $bsal;?></th>
</tr>
<tr>
<th>pf deduction</th>
<th><?php echo $pf;?></th>
</tr>
<tr>
<th>da</th>
<th><?php echo $da;?></th>
</tr>
<tr>
<th>hra</th>
<th><?php echo $hra;?></th> </tr>
<tr>
<th>IT</th>
<th><?php echo $it;?></th>
</tr>
<tr>
<th>Netsalary</th>
<th><?php echo $netsal;?></th>
</tr>
</table>
</body>
</html>
OUTPUT :
Ex.No.5a FILE UPLOAD
file_upload.php
<?php
session_start();
?>
<!DOCTYPE html>
<html>
<head>
<title>FILE upload</title>
</head>
<body>
<form action="uploadfile.php" method="POST" enctype="multipart/form-data">
<h2>UPLOAD EMPLOYEES SALARY FILE</h2>
<br>
<br>
<h4> supported file types: doc,docx,pdf,ppt,pptx,rar</h4></font>
<br><br>
<input type="file" name="uploadedFile" /><br><br><br>
<a href="#">
<button type="submit" name="uploadBtn" value="upload"/>
<span>upload</span>
<div CLASS="liquid"></div>
</a>
</form>
</body>
</html>
uploadfile.php
<html>
<head>
</head>
<body align="center" bgcolor="#f39c12" >
<font size="50px">
<?php
session_start();
$message='';
if(isset($_POST['uploadBtn'])&&$_POST['uploadBtn']=='upload')
{
if(isset($_FILES['uploadedFile']) && $_FILES['uploadedFile']['error']===UPLOAD_ERR_OK)
{
//GET DETAILS OF THE UPLOADED FILES
$fileTmpPath=$_FILES['uploadedFile']['tmp_name'];
$fileName=$_FILES['uploadedFile']['name'];
$fileSize=$_FILES['uploadedFile']['size'];
$fileType=$_FILES['uploadedFile']['type'];
$fileNameCmps=explode(".",$fileName);
$fileExtension=strtolower(end($fileNameCmps));
//sanitize file-name
$newFileName=($fileName).'.'.$fileExtension;
//check file name has if one of the file extension

$allowedfileExtensions=array('jpg','gif','png','zip','txt','xls','doc','rar','pptx','docx','pptx','pdf');
$foldername='C:\wamp64\www\uploadedfile\.';
$filen=$foldername.$newFileName;
if(!file_exists($filen))
{
if(in_array($fileExtension,$allowedfileExtensions))
{
//directery of uploaded files
$uploadFileDir='C:\wamp64\www\uploadedfile\.';
$dest_path=$uploadFileDir.$newFileName;
if(move_uploaded_file($fileTmpPath,$dest_path))
{
$message='file is succesfully uploaded.';
}
else
{
$message='ERROR-there was some error in uploading file to directory...<br>please
make sure the setting is correct...!';
}
}
else
{
$message='upload Failed...<br>NOTE:check file extension
.implode('.'.$allowedfileExtensions)';
}
}
else
{
echo "file ($fileName ) already exists";

}
}
else
{
$message='There is some error in file upload...Please check the following error...'
.$message.='Error' . $_FILES['uploadedFile']['error'];
}
}
$_SESSION['message']=$message;
printf('<b>%s</b>',$_SESSION['message']);
unset($_SESSION['message']);
?>
&nbsp&nbsp<input type=button onClick="location.href='fileindex.php'" value='<< BACK'>
&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp
</body>
</html>
OUTPUT:
File uploaded in the folder (fileuploadedfile):
Ex.No.6a COOKIES IN PHP – PAGE COUNTER

page_counter.php
<?php
$countVisit = 0;
if(isset($_COOKIE['countVisit'])){
$countVisit = $_COOKIE['countVisit'];
$countVisit+1;
}
if(isset($_COOKIE['lastVisit'])){
$lastVisit = $_COOKIE['lastVisit'];
}
// set cookie for countVisit
setcookie('countVisit', $countVisit+1, time()+3600);
// set cookie for last visit
setcookie('lastVisit', date("d-m-Y H:i:s"), time()+3600);
if($countVisit == 0){
echo "Welcome";
} else {
echo "This is your visit number ".$countVisit;
echo '<br>';
echo "Last time, you were here on ".$lastVisit;
}
?>
OUTPUT:
Ex.No.6b SESSIONS IN PHP – TRACK USER
login.html
<html>
<body><center>
<h1>Login Form</h1><pre>
<form action="mydisplay.php" method="post">
Username:<input type="text" name="user" ><br><br>
Password:<input type="password" name="username" >
<button type="submit" >submit</button>
</form></pre>
</center>
</body>
</html>

mydisplay.php
<body>
<center>
<pre>
<?php
session_start();
$user=$_POST['user'];
$_SESSION['user']=$user;
date_default_timezone_set('Asia/Kolkata');
$time=date(" h:i:s ") ;
$_SESSION['time']=$time;
echo "welcome " .$_SESSION['user']."<br><br>";
echo "your login time is ".$_SESSION['time'];
?>
<input type=button onclick=location.href='logout.php' value='Logout'>
</pre>
</center>
</body>
</html>

logout.php
<html>
<body>
<center><pre>
<?php
session_start();
session_destroy();
echo "<script>alert('session expired');</script>";
date_default_timezone_set('Asia/Kolkata');
$time=date(" h:i:s ") ;
echo "Your logged out time is:$time";
?>
<input type=button onclick=location.href='testlogin.php' value='To login'>
</pre>
</center>
</body>
</html>
OUTPUT:
Ex.No.7a IMAGE UPLOAD IN PHP WITH BIO DATA –
JOB APPLICATION
biodata.html
<html>
<body bgcolor="lightblue">
<title>Bio data</title>
<h2>Enter your details</h2>
<form action="biodisplay.php" method="POST" enctype="multipart/form-data">
Name:&emsp;&emsp;&emsp;&emsp;&emsp;<input type="text" name="na"
required><br><br>
Father's Name:&emsp;&ensp;&nbsp;<input type="text" name="fname" required><br><br>
Mother's Name:&emsp;&nbsp;<input type="text" name="mname" required><br><br>
<label for="name">Age:&emsp;&emsp;&emsp;&emsp;&emsp;&ensp;</label>
<input type="number" name="age" required><br><br>
Gender:&emsp;&emsp;&emsp;&emsp;<input type="radio" name="gender"
value="m">Male
<input type="radio" name="gender" value="f">Female
<input type="radio" name="gender" value="o">Others<br><br>
Email:&emsp;&emsp;&emsp;&emsp;&emsp;<input type="email" name="email"
required><br><br>
Educational Qualification:<br>
<input type="checkbox" name="edu" value="sslc">SSLC<br>
&nbsp;&nbsp;&nbsp;&nbsp;Percentage:<input type="text" name="sslc"><br>
<input type="checkbox" name="edu1" value="hsc">HSC<br>
&nbsp;&nbsp;&nbsp;&nbsp;Percentage:<input type="text" name="hsc"><br>
<input type="checkbox" name="edu2" value="ug">UG<br>
&nbsp;&nbsp;&nbsp;&nbsp;Percentage:<input type="text" name="ug"><br><br>
<input type="checkbox" name="edu3" value="pg">PG<br>
&nbsp;&nbsp;&nbsp;&nbsp;Percentage:<input type="text" name="pg"><br><br>
<label for="address">Address:<br></label><textarea name="address" cols="45"
rows="5"></textarea><br><br>
City:&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&nbsp;<input type="text" name="city"
required><br><br>
Pincode:&emsp;&emsp;&emsp;&emsp;&ensp;&nbsp;<input type="text" name="pin"
required><br><br>
Nationality:&emsp;&emsp;&emsp;&ensp;<input type="text" name="nation"
required><br><br>
Marital Status:&emsp;&emsp;&ensp;<input type="text" name="status" required><br><br>
Photo:<input type="file" name="photo" id="photo"><br><br>
<input type="submit" value="Submit">
</form>
</body>
</html>

biodisplay.php
<html>
<title> Bio-Data Display</title>
<head><center>
<style>
fieldset{
width: 650px;
height: 850px;
background-color: silver;
text-align: left;
padding: 10px;
border: 4px solid black;
}
#image{
border: 4px solid black;
padding: 3px;
margin-left: 400px;
margin-bottom: 30px;
height: 150px;
width: 140px;
border-radius: 15px; }
</style> </head>
<body>
<fieldset>
<center> <h1> Bio-Data</h1> </center>
<?php
if($_SERVER["REQUEST_METHOD"]=="POST")
{
$name=$_POST['na'];
$fna=$_POST['fname'];
$mna=$_POST['mname'];
$age=$_POST['age'];
$gender=$_POST['gender'];
if($gender=="m")
{
$gen="Male";
}
else if($gender=="f")
{
$gen="Female";
}
else if($gender=="o")
{
$gen="Others";
}
$email=$_POST['email'];
$addr=$_POST['address'];
$city=$_POST['city'];
$pin=$_POST['pin'];
$nation=$_POST['nation'];
$ms=$_POST['status'];
$photo=$_FILES['photo']['name'];
$photo1=$_FILES['photo']['tmp_name'];
$folder='image/';
move_uploaded_file($photo1,$folder.$photo);
echo "<div id=image>";
echo "<img src=image/$photo width=140px height=150px ><br><br>";
echo "</div>";
echo "<B>Name &emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&ensp;:
</B>".$name."<br><br>";
echo "<B>Father's Name &emsp;&emsp;&ensp;&nbsp;: </B>".$fna."<br><br>";
echo "<B>Mother's Name &emsp;&emsp;&nbsp;&nbsp;: </B>".$mna."<br><br>";
echo "<B>Age
&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;&ensp;
&ensp;&ensp;: </B>".$age."<br><br>";
echo "<B>Gender &emsp;&emsp;&emsp;&emsp;&emsp;&ensp;&ensp;:
</B>".$gen."<br><br>";
echo "<B>Email&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&ensp;&ensp;:
</B>".$email."<br><br>";
echo "<B>Address&emsp;&emsp;&emsp;&emsp;&emsp;&ensp;&ensp;:</B>
".$addr."<br><br>";
if(isset($_POST["edu"])&& isset($_POST['sslc']))
{
echo "<table border=2px><tr><th><B>Educational
Qualification</B></th><th><B>Percentage</B></th></tr>";
echo "<tr><th>SSLC</th><th>".$_POST['sslc']."</th></tr>";
}
if(isset($_POST["edu1"])&& isset($_POST['hsc']))
{
echo "<tr><th>HSC</th><th>".$_POST['hsc']."</th></tr>";
}
if(isset($_POST["edu2"])&& isset($_POST['ug'])){
echo "<tr><th>UG</th><th>".$_POST['ug']."</th></tr>";
}
if(isset($_POST["edu3"])&& isset($_POST['pg'])){
echo "<tr><th>PG</th><th>".$_POST['pg']."</th></tr>";
}
echo "<B>City&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&ensp;:</B>
".$city."<br><br>";
echo "<B>Pincode&emsp;&emsp;&emsp;&emsp;&emsp;&ensp;&ensp;:</B>
".$pin."<br><br>";
echo "<B>Nationality&emsp;&emsp;&emsp;&emsp;&ensp;:</B> ".$nation."<br><br>";
echo "<B>Marital Status&emsp;&emsp;&ensp;&ensp;:</B> ".$ms."<br><br>";
} ?>
</fieldset></center>
</body> </html>
OUTPUT:
File uploaded in the folder (image):
Ex.No.8 CUSTOMER PURCHASE DETAILS
login.php
<?php
$hn = 'localhost';
$db = 'customer';
$un = 'root';
$pw = '';
?>

customer.html
<html>
<head>
<title>customer details</title>
</head>
<body>
<h1 align="center">CUSTOMER DETAILS</h1>
<form name="form1" method="POST" action="pur_det.php">
<div align="center">
<p>Enter customer no:<input type="text" name="cno"></p>
<input type="submit">
</form>
</body>
</html>

pur_det.php
<?php
require_once 'login.php';
$conn = new mysqli($hn, $un, $pw, $db);
if ($conn->connect_error) die($conn->connect_error);
echo "<h2><B>Customer Purchase Details</B></h2>";
$cno=$_REQUEST['cno'];
$query = "SELECT * FROM customer where cid=$cno";
$result = $conn->query($query);
if (!$result) die ("Database access failed: " . $conn->error);
$rows = $result->num_rows;
echo "<table border='1' align='left'><tr> <th>Customer ID</th><th>Customer
Name</th><th>Date of purchase</th><th>Number of
items</th><th>Amount</th></tr>";
for ($j = 0 ; $j < $rows ; ++$j)
{
$result->data_seek($j);
$row = $result->fetch_array(MYSQLI_NUM);
echo "<tr>";
for ($k = 0 ; $k < 5 ; ++$k) echo "<td>$row[$k]</td>";
echo "</tr>";
}
echo "</table>";
echo <<<_END
<br><br>
<input type=button onClick="location.href='customer.html'" value='Home'>
_END
?>
Creating table in php myadmin:

Displaying table customer in php my admin:


OUTPUT:
Ex.No.9 STUDENT MANIPULATE
login.php
<?php
$hn = 'localhost';
$db = 'student';
$un = 'root';
$pw = '';
?>

student.html
<html>
<head>
<title>student details</title>
</head>
<body>
<h2 align="center"><B>Student Marksheet Manipulation</B></h2><br>
<h2><B>Click on your choice below</B></h2><br>
&nbsp&nbsp<input type=button onClick="location.href='stu_insert.php'" value='Insert'>
&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp<input type=button
onClick="location.href='stu_update.php'" value='Update'>
&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp<input type=button
onClick="location.href='stu_view.php'" value='View'>
&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp<input type=button
onClick="location.href='stu_delete.php'" value='Delete'>
</body>
</html>

stu_insert.php
<?php
require_once 'login.php';
$conn = new mysqli($hn, $un, $pw, $db);
if ($conn->connect_error) die($conn->connect_error);
$query = "INSERT INTO student
VALUES('Laura',05,75,82,99,79,80,(75+82+99+79+80),(75+82+99+79+80)/5)";
$result = $conn->query($query);
if (!$result) die ("Database access failed: " . $conn->error);
echo "One row created";
echo <<<_END
<br><br>
<input type=button onClick="location.href='student.html'" value='Home'>
_END
?>

stu_update.php
<?php
require_once 'login.php';
$conn = new mysqli($hn, $un, $pw, $db);
if ($conn->connect_error) die($conn->connect_error);
$query = "UPDATE student SET Name='Charlie' WHERE rno=5";
$result = $conn->query($query);
if (!$result) die ("Database access failed: " . $conn->error);
echo "One row updated";
echo <<<_END
<br><br>
<input type=button onClick="location.href='student.html'" value='Home'>
_END
?>
stu_view.php
<?php
require_once 'login.php';
$conn = new mysqli($hn, $un, $pw, $db);
if ($conn->connect_error) die($conn->connect_error);
$query = "SELECT * FROM student";
$result = $conn->query($query);
if (!$result) die ("Database access failed: " . $conn->error);
$rows = $result->num_rows;
echo "<table border='1' align='left'><tr>
<th>Name</th><th>Rno</th><th>M1</th><th>M2</th><th>M3</th><th>M4</th>
<th>
M5</th><th>TOTAL</th><th>AVERAGE</th></tr>";
for ($j = 0 ; $j < $rows ; ++$j)
{
$result->data_seek($j);
$row = $result->fetch_array(MYSQLI_NUM);
echo "<tr>";
for ($k = 0 ; $k < 9 ; ++$k)
echo "<td>$row[$k]</td>";
echo "</tr>";
}
echo "</table>";
echo <<<_END
<br><br>
<input type=button onClick="location.href= student .html'" value='Home'>
_END
?>
stu_delete.php
<?php
require_once 'login.php';
$conn = new mysqli($hn, $un, $pw, $db);
if ($conn->connect_error) die($conn->connect_error);
$query = "DELETE FROM student WHERE name='Charlie'";
$result = $conn->query($query);
if (!$result) die ("Database access failed: " . $conn->error);
echo "one row deleted";
echo <<<_END
<br><br>
<input type=button onClick="location.href= student .html'" value='Home'>
_END
?>
creating table in php myadmin:

Displaying table in php myadmin:


OUTPUT:

Inserting row into the table:

Changes done on php myadmin:


Updating row into the table:

Changes done on php myadmin:


Viewing rows in the table:

Changes done on php myadmin:


Deleting rows in the table:

Changes done on php myadmin:


Ex.No.10 DIGITAL LIBRARY ACCESS
login.php
<?php
$hn = 'localhost';
$db = 'library';
$un = 'root';
$pw = '';
?>

library.html
<html>
<head>
<center>
<h1><b>BISHOP HEBER COLLEGE</b></h1>
<h3>AUTONOMOUS</h3>
<h4>(for more info visit bhc.edu.in)</h4><br>
<h2><b><br>DIGITAL LIBRARY</b></h2><br>
</center>
</head>
<body bgcolor="dodgerblue">
<form action="" method="POST">
<pre>
<center>
<input type=button id="button" onClick="location.href=' liblogin1.html '" value='LOGIN'>
<BR><br><br>
<input type=button id="button" onClick="location.href=' libsignup1.html '" value='SIGN
UP'>
</center>
</pre>
</form>
</body>
</html>

liblogin1.html
<html>
<head>
<center>
<h1><b>BISHOP HEBER COLLEGE</b></h1>
<h3>AUTONOMOUS</h3>
<h4>(for more info visit bhc.edu.in)</h4><br>
<h2><b><br>DIGITAL LIBRARY - LOGIN</b></h2><br>
</center>
</head>
<body bgcolor="dodgerblue">
<form action=" liblogin2.php " method="POST">
<pre><center>
USERNAME<input type="text" name="user" id="name" required><br>
PASSWORD<input type="password" name="pass" id="name" required><br>
<input type="submit"
name="submit" value="LOGIN" id="button">
</center></pre>
</form>
</body>
<input type=button id="button" onClick="location.href='library.html'" value='BACK'>
</html>
liblogin2.php
<html>
<input type="button" id="button" onClick="location.href='liblogin1.html'" value='LOGOUT'>
<center>
<h1><b>BISHOP HEBER COLLEGE</b></h1>
<h3>AUTONOMOUS</h3>
<h4>(for more info visit bhc.edu.in)</h4><br>
<h2><b><br>DIGITAL LIBRARY</b></h2><br>
</center>
<body bgcolor="pink"><br><br>
<button onclick="window.print()">print</button>
<?php
require_once 'login.php';
$conn = new mysqli($hn,$un,$pw,$db);
if ($conn->connect_error) die($conn->connect_error);
$a=$_REQUEST['user'];
$b=$_REQUEST['pass'];
$query="select * from liblogin where user='$a' && pass='$b'";
$result =mysqli_query($conn,$query);
$num=mysqli_num_rows($result);
if($num){
echo "ACCESS GRANTED !!!<br>
<br>";
echo "USER - $a<BR><BR>";
echo "WELCOME TO DIGITAL LIBRARY<br><br><br><br>";
echo "<b>10 Best Java Books for Beginners & Advanced
Programmers</b><br><br><br><br>
Here, we have assembled a list of 11 excellent Java books to advance your learning in
Java.<br><br><br><br>
<br><br>
<br>
<br>
<br>
<b>
1. Core Java Volume I – Fundamentals<br>
Core Java Volume I--Fundamentals (11th Edition)</b><br>
<br>
Author – Cay S. Horstmann<br>
Latest Edition – 11th Edition<br>
Publisher – Prentice Hall<br><br><br>
<br>Core Java Volume I – Fundamentals is a Java reference book (Best book for Java)that
offers a detailed explanation of various features of Core Java, including exception handling,
interfaces, and lambda expressions.<br> Significant highlights of the book include simple
language, conciseness, and detailed examples.<br> The latest edition of the Core Java
Volume I – Fundamentals comprehensively updated for covering Java SE 9, 10 & 11.<br>
The book helps Java programmers develop an ability to write highly robust and
maintainable code.
<br>
<br><br>
<br>
<br>
<br>
<b>
2. Effective Java<br>
Effective Java<br></b>
Author – Joshua Bloch<br>
Latest Edition – 3rd Edition<br>
Publisher – Addison Wesley<br>
A must-have book for every Java programmer and Java aspirant, Effective Java makes up
for an excellent complementary read with other Java books or learning material. The book
offers 78 best practices to follow for making the code better. Effective Java divides all the
mentioned best practices into 11 distinct sections, such as Concurrency, Generics, and
Methods, to make it easier for the reader to grasp it all. The book offers something to Java
programmers of any skill level. Effective Java is written by Joshua Bloch, who is also the
author of many key Java classes and API, including java.lang and Java Collection framework.
The context of the latest edition of the book built around Java 7, 8, and 9.
<br>
<br>
<br>
<br>
<br>
<b>
3. Java: A Beginner’s Guide<br>
A beginner's Guide<br></b>
<br>
Author – Herbert Schildt<br>
Latest Edition – 8th Edition<br>
Publisher – McGraw-Hill Education<br>
<br>
If you are a seasoned Java programmer looking to enhance your Java knowledge, don’t be
averted by the title of the book, Java: A Beginner’s Guide. It is, in fact, one of the most
comprehensive books for learning Java. Anyone with basic programming knowledge can
easily benefit from the Java: A Beginner’s Guide. The Java book covers all concepts pertains
to Core Java. The latest edition of the Java: A Beginner’s Guide is fully revised to include
Java 11 SE. The book offers several hands-on exercises as well as a quiz section at the end
of every chapter to let the readers self-evaluate their learning.
<br><br><br>
<br>
<br>
<b>
4. Java - The Complete Reference<br>
Java Complete Reference</b><br>
<br>
Author – Herbert Schildt<br>
Latest Edition – 11th Edition
Publisher – McGraw Hill Education<br>
<br>
<br>Java - The Complete Reference is a convenient Java reference book with over 1000
pages. It contains every aspect of Java that you need to master. In addition to examining
essential portions of the Java API library, Java - The Complete Reference covers
fundamental programming principles, Java language syntax, and keywords. The book is full
of discussions and apt examples to better Java learning.
<br>
<br>You can buy the book here.
<br><br>
<br>
<br>
<br>
<br>
<b>
<br>5.Head First Java
<br>Head First Java</b>
<br>
<br>Author – Kathy Sierra & Bert Bates
<br>Latest Edition – 2nd Edition
<br>Publisher – Shroff/O’Reilly
<br>
<br>The most important selling points of Head First Java is its simplicity and supereffective
real-life analogies that pertain to the Java programming concepts. It is also the
best book to learn java and to start your learning journey with Java Development. Head
First Java covers almost all OOPS concepts and fascinatingly explains them. Despite several
readers claiming it to be a dated book, as it covers nothing beyond Java 5.0, Head First Java
is still found on the shelves of numerous Java veterans. Thus, it a must-have book for every
Java pursuer and developer.
<br><br>
You can buy the book here.
<br><br>
Some important topics covered by Head First Java include common OO mistakes,
distributed programming with RMI and network sockets, and threads. Additionally, the
book overs 42 mind-bending puzzles that will ensure a better understanding of Java.
<br><br><br>
<br>
<br>
<br>
<br>
<br>";
}else{
echo "Invalid username/password";
}
?>
</body>
</html>

libsignup1.html
<html>
<head>
<center>
<h1><b>BISHOP HEBER COLLEGE</b></h1>
<h3>AUTONOMOUS</h3>
<h4>(for more info visit bhc.edu.in)</h4><br>
<h2><b><br>DIGITAL LIBRARY - REGISTER</b></h2><br>
</center>
</head>
<body bgcolor="dodgerblue">
<form action=" libsignup2.php " method="POST">
<pre>
ENTER USERNAME : <input type="text" name="user" id="name" required><br>
ENTER PASSWORD : <input type="password" name="pass" id="name" required><br>
ENTER ROLLNO. : <input type="number" name="rollno" id="name" required><br>
ENTER DEPARTMENT : <input type="text" name="department" id="name"
required><br>
ENTER MOBILE.NO. : <input type="number" name="mobileno" id="name" required><br>
ENTER D.O.B : <input type="date" name="dob" id="name" required><br>
ENTER MAIL-ID : <input type="email" name="mailid" id="name" required><br>
<center><input type="submit" name="submit" value="SIGN UP " id="button"></center>
</pre>
</form>
</body>
<input type=button id="button" onClick="location.href='lindex.php'" value='BACK'>
</html>
libsignup2.php
<html>
<head>
<center>
<h1><b>BISHOP HEBER COLLEGE</b></h1>
<h3>AUTONOMOUS</h3>
<h4>(for more info visit bhc.edu.in)</h4><br>
<h2><b><br>DIGITAL LIBRARY</b></h2><br>
</center>
</head>
<body align="center" bgcolor="dodgerblue">
<br><br>
<?php
require_once 'login.php';
$conn = new mysqli($hn, $un, $pw, $db);
if ($conn->connect_error) die($conn->connect_error);
$a=$_REQUEST['user'];
$b=$_REQUEST['pass'];
$c=$_REQUEST['rollno'];
$d=$_REQUEST['department'];
$e=$_REQUEST['mobileno'];
$f=$_REQUEST['dob'];
$g=$_REQUEST['mailid'];
$query="insert into liblogin(user,pass,rollno,department,mobileno,dob,mailid)
values('$a','$b','$c','$d','$e','$f','$g')";
$result = $conn->query($query);
if (!$result) die ("username is already taken...! <br> try a different name <br>Database
access failed: " . $conn->error);
echo "PROFILE CREATED !";
echo <<<_END
<br><br>
_END
?>
</body>
<input type=button id="button" onClick="location.href='libsignup1.html'" value='BACK'>
<input type=button onClick="location.href='library.html'" value='home'>
</html>
Creating table in php myadmin:

Displaying value in php myadmin:


OUTPUT:

You might also like