Sample Code for Group Assignment
Sample Code for Group Assignment
Aim: Write a PHP program to select data and show into table format.
<html>
<head>
<title>Create Database. </title>
</head>
<body>
<?php
$con = mysql_connect("localhost","root","");
if(!$con)
{
die("not opened");
}
echo "Connection open"."</br>";
$db = mysql_select_db("studinfo",$con);
if(!$db)
{
die("Database not found".mysql_error());
}
echo "Database is selected"."</br>";
?>
</body>
</html>
O/P:
Connection open
Database is selected
ID Name Branch
9 Anil J Basantani CE
9 Anil J Basantani CE
9 Anil J Basantani CE
Practical-19
AIM: - Create a student Registration in PHP and Save and Display the
student Records.
<html>
<head>
<title>general form</title>
</head>
<body bgcolor="aakk">
<form action = "<?php $_PHP_SELF ?>" method = "POST">
Name:
<input type = "text" name = "txtname">
<br><br>
Roll no.:
<input type = "text" name = "txtr_no">
<br><br>
Gender:
<input type = "text" name = "txtgen">
<br><br>
Address:
<textarea name = "add" type = "textarea"></textarea>
<br><br>
$name = strval($_POST['txtname']);
$rollno = intval($_POST['txtr_no']);
$gender = strval($_POST['txtgen']);
$address = strval($_POST['add']);
mysql_close($con);
}
}
?>
O/P:
PAPER SOLUTION
Extra-1
Form fill.php
<html>
<head>
<title>insert data in form</title>
</head>
<body>
<form action = "getdata.php" method = "POST">
Name:
<input type = "text" name = "txtname">
<br><br>
Roll no.:
<input type = "text" name = "txtr_no">
<br><br>
Address:
<textarea name = "add" type = "textarea"></textarea>
<br><br>
Contyact No:
<input type = "text" name = "txtc_no">
<br><br>
Email ID:
<input type = "text" name = "txteid">
<br><br>
<html>
<head>
<title>get data from another page</title>
</head>
<body>
<?php
?>
</body>
</html>
O/P:
Extra-2
AIM: - Write a program to read customer information like c_no, c_name,
item_purchased and mob_no from customer table and display all this
information in table format on output screen.
<html>
<head>
<title>display data in table format</title>
</head>
<body>
<?php
$con = mysql_connect("localhost","root","");
if(!$con)
{
die("not connected".mysql_error());
}
echo "Connection open"."<br/>";
$sldb = mysql_select_db("coust",$con);
if(!$sldb)
{
die("not found".mysql_error());
}
echo "Database selected"."<br/>";
$query = "select * from customer";
$sql = mysql_query($query);
O/P:
Connection open
Database selected
C_No C_Name Item_Purchased Mob_no
1 Anil Book 2147483647
2 Yogesh Marker 2147483647
Extra-3
AIM: - Write PHP code to upload image.
<?php
$result=0;
}
?>
<html>
<head>
</head>
<body>
</form>
<br>
<?php
?>
</body>
</html>
O/P
Browse for Image (jpg): Upload
Upload File
Extra-4
AIM: - Write a program that keeps track of how many times a visitor has
loaded the page.
<html>
<head>
<title>php counter</title>
</head>
<body>
<?php
session_start();
if(isset($_SESSION['counter']))
{
$_SESSION['counter'] += 1;
}
else
{
$_SESSION['counter'] = 1;
}
echo "You have visited this page ".$_SESSION['counter']." time in this session";
?>
</body>
</html>
O/P:
You have visited this page 1 time in this session
Extra-5
AIM: Write a program that displays a different message based on
time of day. For example page should display “Good Morning” if it is
accessed in the morning.
<?PHP
//Change the messages to what you want.
$afternoon = "Good afternoon! ";
$evening = "Good evening! ";
$late = "Working late? ";
$morning = "Good morning! ";
$friday= "Get ready for the weekend! ";
//Get the current hour
$current_time = date('G');
?>
O/P :-
Good morning! (Its base on Current Time)