Department of Information Technology
Output:
Web Designing Using PHP & MySQL(3361603)
Department of Information Technology
Department of Information Technology
Output :
Department of Information Technology
PRACTICAL:26
AIM: Write a PHP script to connect MySQL server from your website.
File: [Link]
<?php
$con=mysqli_connect("localhost","root","");
$db=mysqli_select_db($con,"kisaan");
if($db)
{
echo "<h1>Connection With MYSQL</h1>";
echo "<h3>[Link] file connected with MYSQL</h3>";
echo "<h3>Connection With database kisaan</h3>";
echo "<h2>[Link] file connected with database kisaan</h32";
} echo "connection successful";
else
{
} echo"connection invalid";
?>s
Output:
Web Designing Using PHP & MySQL(3361603)
Department of Information Technology
PRACTICAL: 27
AIM: 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.
File:[Link]
<html>
<head>
<style>
h3{text-align:center;}
</style>
</head>
<title></title>
<body>
<form method="POST" >
<table border="1" align="center" background>
<th colspan="2"><h1>Customer Info</h1></th>
<tr>
<td>
<h3>Customer number</h3>
</td>
<td>
<input type="text" name="cno">
</td>
</tr>
<tr>
<td>
<h3>Customer name</h3>
</td><td>
<input type="text"name="cnm">
</td>
Web Designing Using PHP & MySQL(3361603)
Department of Information Technology
</tr>
<tr><td>
<h3>Item select</h3>
</td><td>
<input type="text"name="itm"></td></tr>
<tr>
<td>
<h3>Mobile</h3>
</td><td>
<input type="text"name="mo">
</td>
</tr>
<tr>
<td align="center">
<input type="submit" name="submit">
</td>
<td align="center">
<input type="submit" value="view" name="vw">
</td>
</tr>
</table>
</form>
<?php
if (isset($_POST['vw'])) {
header("location:[Link]");
}
if (isset($_POST['submit']))
{
$cust_no=$_POST['cno'];
$cust_name=$_POST['cnm'];
Web Designing Using PHP & MySQL(3361603)
Department of Information Technology
$item=$_POST['itm'];
$mobile_no=$_POST['mo'];
$con = mysqli_connect("localhost","root","");
mysqli_select_db($con,"extra");
$sql = "INSERT INTO customer (cno,cnm,itm,mo) VALUES('".$cust_no."','".
$cust_name."','".$item."','".$mobile_no."')";
$result=mysqli_query($con,$sql);
if($result){
echo "<h3>successfull</h3>";
}
else{
echo"";
}
mysqli_close($con);
}
?>
</td></tr>
</table>
</body>
</html>
File:pr27view
<html>
<body>
<center>
<h1>Customer Information</h1>
<table border="1">
<tr>
<th>Customer Id</th>
<th>Customer Name</th>
<th>Item Purchase</th>
Web Designing Using PHP & MySQL(3361603)
Department of Information Technology
<th>Mobile no.</th>
</tr>
<?php
$con = mysqli_connect("localhost","root","");
mysqli_select_db($con,"extra");
$sql = "SELECT * FROM customer";
$result=mysqli_query($con,$sql);
while($row=mysqli_fetch_array($result))
{
$no=$row['cno'];
$name=$row['cnm'];
$item=$row['itm'];
$mno=$row['mo'];
?>
<!--<table border="1">-->
<tr>
<td><?php echo $no; ?></td>
<td><?php echo $name; ?></td>
<td><?php echo $item; ?></td>
<td><?php echo $mno; ?></td>
</tr>
<?php
}
$records=mysqli_num_rows($result);
?>
<tr>
<td colspan="4" align="center"><?php echo $records." records";?></td>
</tr>
<?php
mysqli_close($con);
Web Designing Using PHP & MySQL(3361603)
Department of Information Technology
?>
</table>
</body>
</html>
Output:
Web Designing Using PHP & MySQL(3361603)
Department of Information Technology
PRACTICAL: 28
AIM: Write a program to edit name of customer to “Bob” with cust_no =1,
and to delete record with cust_no=3.
File:[Link]
<html>
<body>
<center>
<h1>Customer Information</h1>
<table border="1">
<tr>
<th>Customer Id</th>
<th>Customer Name</th>
<th>Item Purchase</th>
<th>Mobile no.</th>
<th>Delete</th>
<th>Edit</th>
</tr>
<?php
$con = mysqli_connect("localhost","root","");
mysqli_select_db($con,"extra");
$sql = "SELECT * FROM customer";
$result=mysqli_query($con,$sql);
while($row=mysqli_fetch_array($result))
{
$no=$row['cno'];
$name=$row['cnm'];
$item=$row['itm'];
$mno=$row['mo'];
?>
Web Designing Using PHP & MySQL(3361603)
Department of Information Technology
<!--<table border="1">-->
<tr>
<td><?php echo $no; ?></td>
<td><?php echo $name; ?></td>
<td><?php echo $item; ?></td>
<td><?php echo $mno; ?></td>
<td> <a href="[Link]
<td> <a href="[Link]
</tr>
<?php
}
$records=mysqli_num_rows($result);
?>
<tr>
<td colspan="4" align="center"><?php echo $records." records";?></td>
</tr>
<?php
mysqli_close($con);
?>
</table>
</body>
</html>
File:[Link]
<!DOCTYPE html>
<html>
<body>
<form method="POST">
<table border="1" align="center" cellpadding="15">
<h1 align="center">Edit Customer Info</h1>
Web Designing Using PHP & MySQL(3361603)
Department of Information Technology
<tr><td>
<h2>Customer id:</h2>
</td><td>
<input type="text" name="cno">
</td></tr>
<tr><td>
<h2>Customer name:</h2>
</td><td>
<input type="text" name="cnm">
</td>
</tr>
<tr>
<td>
<h2>Item purchase:</h2>
</td><td>
<input type="text" name="itm">
</td></tr>
<tr>
<td>
<h2>Mobile no.:</h2>
</td>
<td>
<input type="text" name="mo">
</td></tr>
<tr>
<td align="center" colspan="2">
<input type="submit" name="submit">
</td>
</tr>
</table>
Web Designing Using PHP & MySQL(3361603)
Department of Information Technology
<?php
if (isset($_POST['submit'])) {
$cust_no=$_POST['cno'];
$cust_name=$_POST['cnm'];
$item=$_POST['itm'];
$mobile_no=$_POST['mo'];
$con = mysqli_connect("localhost","root","");
mysqli_select_db($con,"extra");
$sql = "UPDATE customer SET cnm='$cust_name',itm='$item',mo='$mobile_no'
WHERE cno='$cust_no'";
$result=mysqli_query($con,$sql);
if($result){
echo"Update successfull";
}
else{
echo"Unsuccessfull";
}
mysqli_close($con);
}
?>
</form>
</body>
</html>
File:[Link]
<!DOCTYPE html>
<html>
<body>
<form method="POST">
<h1 align="center">Enter Customer Id to Delete</h1>
<table border="1" align="center">
Web Designing Using PHP & MySQL(3361603)
Department of Information Technology
<tr><td>
<h2>Customer no.:</h2>
</td><td>
<input type="text" name="cno">
</td>
</tr><tr>
<td align="center" colspan="2">
<input type="submit" name="submit">
</td>
</tr>
</table>
<?php
if (isset($_POST['submit'])) {
$con = mysqli_connect("localhost","root","");
mysqli_select_db($con,"extra");
$id = $_POST['cno'];
$sql = "DELETE FROM customer WHERE cno = '$id';";
$result=mysqli_query($con,$sql); if($result)
{
echo"Deleted Successfully";
}
else{
echo"Unsuccessful";
}
mysqli_close($con);
}
?>
</form>
</body>
</html>
Web Designing Using PHP & MySQL(3361603)
Department of Information Technology
Output
[1] Edit Customer with cust_no=1 cust_name=bob
Web Designing Using PHP & MySQL(3361603)
Department of Information Technology
[2] delete customer with Cust_no=3
Web Designing Using PHP & MySQL(3361603)
Department of Information Technology
PRACTICAL: 29
AIMWrite 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.
<html>
<head>
<title>Form</title>
</head>
<body>
<form method="POST">
<table border="2" align="center" cellpadding="11">
<th colspan="2"><h1>EMPLOYEE DATA</h1></th>
<tr><td>
<h2>Employee id:</h2>
</td><td>
<input type="text" name="emp_no">
</td></tr>
<tr><td>
<h2>Employee name:</h2>
</td><td>
<input type="text" name="emp_name">
</td></tr>
<tr><td>
<h2>Designation:</h2>
</td><td>
<input type="text" name="designation">
Web Designing Using PHP & MySQL(3361603)
Department of Information Technology
</td></tr>
<tr><td>
<h2>Salary:</h2>
</td><td>
<input type="text" name="salary">
</td></tr>
<tr><td align="center">
<input type="submit" name="submit">
</td><td align="center">
<input type="submit" name="click" value="View Records">
</td></tr>
</table>
<?php
if (isset($_POST['click']))
header("location:[Link]");
if (isset($_POST['submit'])) {
$emp_no=$_POST['emp_no'];
$emp_name=$_POST['emp_name'];
$designation=$_POST['designation'];
$salary=$_POST['salary'];
$con = mysqli_connect("localhost","root","");
mysqli_select_db($con,"extra");
$sql = "INSERT INTO emp (emp_no,emp_name,designation,salary) VALUES('".
$emp_no."','".$emp_name."','".$designation."','".$salary."')";
Web Designing Using PHP & MySQL(3361603)
Department of Information Technology
$result=mysqli_query($con,$sql);
?>
<h1 align="center">
<?php
if($result)
{ echo"Successfull";
else{
echo"Unsuccessful";
mysqli_close($con);
?>
</form>
</body>
</html>
File:[Link]
<html>
<body>
<center>
<h1>Employee Data</h1>
<table border="1">
<tr>
<th>Employee Id</th>
<th>Employee Name</th>
<th>Designation</th>
<th>Salary</th>
Web Designing Using PHP & MySQL(3361603)
Department of Information Technology
</tr>
<?php
$con = mysqli_connect("localhost","root","");
mysqli_select_db($con,"extra");
$sql = "SELECT * FROM emp";
$result=mysqli_query($con,$sql);
while($row=mysqli_fetch_array($result))
{
$no=$row['emp_no'];
$name=$row['emp_name'];
$designation=$row['designation'];
$salary=$row['salary'];
?>
<!--<table border="1">-->
<tr>
<td><?php echo $no; ?></td>
<td><?php echo $name; ?></td>
<td><?php echo $designation; ?></td>
<td><?php echo $salary; ?></td>
</tr>
<?php
}
$records=mysqli_num_rows($result);
?>
<tr>
<td colspan="5" align="center"><?php echo $records." records";?></td>
</tr>
<?php
mysqli_close($con);
?>
Web Designing Using PHP & MySQL(3361603)
Department of Information Technology
</table>
</body>
</html>
Output:
Web Designing Using PHP & MySQL(3361603)