0% found this document useful (0 votes)
63 views21 pages

5 Crud

The document contains PHP code for a CRUD (Create, Read, Update, Delete) application. It includes PHP pages for each CRUD function - create.php allows adding a new employee record to a database, read.php displays all employee records from the database, update.php allows updating an existing employee record, and delete.php allows deleting a record. Each PHP page connects to a MySQL database and performs the corresponding CRUD operation on an "emp" table.
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)
63 views21 pages

5 Crud

The document contains PHP code for a CRUD (Create, Read, Update, Delete) application. It includes PHP pages for each CRUD function - create.php allows adding a new employee record to a database, read.php displays all employee records from the database, update.php allows updating an existing employee record, and delete.php allows deleting a record. Each PHP page connects to a MySQL database and performs the corresponding CRUD operation on an "emp" table.
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/ 21

Home.

php
<!DOCTYPE html PUBLIC "...//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>

<title>Untitled Document</title>

<style type="text/css">

body,td,th{

font-size:x-large;

color:#000;

</style></head>

<body>

<div align="center">

<p><strong>CRUD APPLICATION</strong></p>

<p>&nbsp;</p>

<p>&nbsp;</p>

</div>

<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="create.php"> CREATE


</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

<a href="read.php">READ</a>

<a href="update.php">UPDATE</a>&nbsp;&nbsp;&nbsp;&nbsp;

<a href="delete.php">DELETE</a></p>

</body>

</html>
Create.php
<!DOCTYPE html PUBLIC "...//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>

<title>Untitled Document</title>

<style type="text/css">

body,td,th{

font-size:x-large;

</style>

</head>

<body>

<form id="form1" name="form1" method="post" action="create1.php">

<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb
sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs
p;&nbsp;&nbsp;&nbsp;&nbsp;</p>

<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb
sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs
p;&nbsp;&nbsp;&nbsp;&nbsp;

<label>INSERT EMPLOYEE DETAILS<br/>

</label>

&nbsp;</p>

<p>ENTER THE EMPLOYEE NUMBER &nbsp;&nbsp;&nbsp;&nbsp;

<label for="textfield1"></label>

<input type="text" name="textfield1" id="textfield1"/>


</p>

<p>

<label for="textfield2">ENTER THE EMPLOYEE NAME &nbsp;&nbsp;&nbsp;</label>

<input type="text" name="textfield2" id="textfield2"/>

</p>

<p>ENTER THE EMPLOYEE SALARY:

<label for="textfield"></label>

<input type="text" name="textfield" id="textfield"/>

</p>

<p>&nbsp;</p>

<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb
sp;&nbsp;

<input type="submit" name="button" id="button" value="INSERT"/>

</p>

<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb
sp;&nbsp;

<a href="home.php">HOME</a>

<p>&nbsp;</p>

</form>

</body>

</html>
Create1.php
<!DOCTYPE html PUBLIC "...//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>

<title>Untitled Document</title>

</head>

<body>

<?php

error_reporting(0);

$dbhost='localhost';

$dbuser='root';

$dbpass="";

$db="employee";

$conn= new mysqli($dbhost,$dbuser,$dbpass,$db);

if($conn->connect_error)

die('COULD NOT OPEN'.$conn->connect_error());

echo "CONNECTED";

//mysql_select_db('employee',$conn);

$sql="INSERT INTO
emp(empno,empname,empsalary)VALUES('$_POST[textfield1]','$_POST[textfield2]','$_POST[
textfield]')";
if ($conn->query($sql) == TRUE) {

echo "<BR> New record created successfully";

} else {

echo "Error: " . $sql . "<br>" . $conn->error;

$conn->close();

?>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p><a href="home.php">HOME</a></p>

<p>&nbsp;</p>

<p>&nbsp;</p>

</body>

</html>
Read.php
<!DOCTYPE html PUBLIC "...//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>

<title>Untitled Document</title>

<style type="text/css">

body,td,th{

font-family:"Times New Roman",Times,Serif;

font-size:24px;

font-weight:bold;

</style>

</head>

<body>

<form id="form1" name="form1" method="post" action="read.php">

<p align="center">DISPLAY THE EMPLOYEE DETAILS</p>

<p>&nbsp;</p>

<?php

echo "<h2>";

$dbhost='localhost';

$dbuser='root';

$dbpass="";
$db="employee";

$conn= new mysqli($dbhost,$dbuser,$dbpass,$db);

if($conn->connect_error)

die('COULD NOT OPEN'.$conn->connect_error());

echo "CONNECTED";

echo "<br>";

if($result=$conn->query("SELECT * FROM emp"))

echo "<br>";

echo "The Records are:";

echo "<table border='1'>

<tr>

<th>EMPLOYEE NUMBER</th>

<th>EMPLOYEE NAME</th>

<th>EMPLOYEE SALARY</th>

</tr>";

while($row=$result->fetch_row())

echo "<tr>";

echo "<td>".$row[0]."</td>";

echo "<td>".$row[1]."</td>";

echo "<td>".$row[2]."</td>";
}

echo "</table>";

?>

<p><a href="home.php">HOME</a></p>

<p>&nbsp;</p>

<p>&nbsp;</p>

</form>

<p>&nbsp;</p>

<p>&nbsp;</p>

</body>

</html>
Update.php
<!DOCTYPE html PUBLIC "...//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>

<title>Untitled Document</title>

<style type="text/css">

body,td,th{

font-size:24px;

</style>

</head>

<body>

<form id="form1" name="form1" method="post" action="update1.php">

<p align="center"><strong>UPDATE EMPLOYEE DETAILS</strong></p>

<p align="center">&nbsp;</p>

<p><strong>ENTER A EMPLOYEE NUMBER &nbsp;:

<input type="text" name="textfield" id="textfield"/>

</strong></p>

<p>&nbsp;</p>

<p><strong><u>EMPLOYEE DETAILS TO BE MODIFIED:</u></strong></p>


<p>&nbsp;</p>

<p><strong>EMPLOYEE NAME:

<input type="text" name="textfield3" id="textfield3"/>

</strong></p>

<p><strong>EMPLOYEE SALARY:

<input type="text" name="textfield4" id="textfield4"/>

</strong></p>

<p><strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n
bsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="submit" name="button" id="button"
value="UPDATE"/>

</strong></p>

<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb
sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

<a href="home.php">HOME</a></p>

<p>&nbsp;</p>

</form>

<p>&nbsp;</p>

</body>

</html>
Update1.php
<!DOCTYPE html PUBLIC "...//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>

<title>Untitled Document</title>

</head>

<body>

<?php

echo "<h2>";

$dbhost='localhost';

$dbuser='root';

$dbpass="";

$db="employee";

$conn= new mysqli($dbhost,$dbuser,$dbpass,$db);

if($conn->connect_error)

die('COULD NOT OPEN'.$conn->connect_error());

echo "CONNECTED";
if($result=$conn->query("SELECT * FROM emp"))

echo "<br>";

echo "The Records are:";

echo "<table border='1'>

<tr>

<th>EMPLOYEE NUMBER</th>

<th>EMPLOYEE NAME</th>

<th>EMPLOYEE SALARY</th>

</tr>";

while($row=$result->fetch_row())

echo "<tr>";

echo "<td>".$row[0]."</td>";

echo "<td>".$row[1]."</td>";

echo "<td>".$row[2]."</td>";

echo "</tr>";

echo "</table>";

echo "<br>";

$sql="UPDATE emp SET


EMPNAME='$_POST[textfield3]',EMPSALARY='$_POST[textfield4]' WHERE
EMPNO='$_POST[textfield]' ";

$ret=$conn->query($sql);

if(!$ret)
{

die('CANNOT');

echo "UPDATED";

//$result=$conn->query("SELECT * FROM emp");

echo "<br>";

echo "The Records are:";

echo "<table border='1'>

<tr>

<th>EMPLOYEE NUMBER</th>

<th>EMPLOYEE NAME</th>

<th>EMPLOYEE SALARY</th>

</tr>";

if($result=$conn->query("SELECT * FROM emp"))

while($row=$result->fetch_row())

echo "<tr>";

echo "<td>".$row[0]."</td>";

echo "<td>".$row[1]."</td>";

echo "<td>".$row[2]."</td>";

echo "<tr>";

echo "</table>";

}
$conn->close();

echo "<br/>";

echo "<h2>";

?>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p><a href="home.php">HOME</a></p>

<p>&nbsp;</p>

<p>&nbsp;</p>

</body>

</html>
Delete.php
<!DOCTYPE html PUBLIC "...//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>

<title>Untitled Document</title>

<style type="text/css">

body,td,th{

font-family:"Times New Roman",Times,Serif;

font-size:24px;

</style>

</head>

<body>

<form id="form1" name="form1" method="post" action="delete1.php">

<p>&nbsp;</p>

<p><strong>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</strong></p>
<p>&nbsp;</p>

<p><strong>ENTER THE EMPLOYEE NUMBER:

<input type="text" name="textfield" id="textfield"/>

</strong></p>

<p>&nbsp;</p>

<p><strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

<input type="submit" name="button" id="button" value="DELETE"/>

</strong></p>

<p>&nbsp;</p>

<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb
sp;&nbsp;&nbsp;&nbsp;<a href="home.php">HOME</a></p>

<p>&nbsp;</p>

<p>&nbsp;</p>

</form>

<p>&nbsp;</p>

</body>

</html>
Delete1.php
<!DOCTYPE html PUBLIC "...//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>

<title>Untitled Document</title>

</head>

<body>

<?php

error_reporting(0);

$dbhost='localhost';

$dbuser='root';

$dbpass="";

$db="employee";

$conn= new mysqli($dbhost,$dbuser,$dbpass,$db);

if($conn->connect_error)
{

die('COULD NOT OPEN'.$conn->connect_error());

echo "CONNECTED";

echo "<br>";

echo "<br>";

$sql1="DELETE FROM emp WHERE EMPNO='$_POST[textfield]' ";

$ret=$conn->query($sql1);

if(!$ret)

die('CANNOT');

echo "DELETED";

$conn->close();

?>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p><a href="home.php">HOME</a></p>

<p>&nbsp;</p>

<p>&nbsp;</p>

</body>

</html>
OUTPUT:

You might also like