SlideShare a Scribd company logo
2
Most read
3
Most read
5
Most read
Step:1 Create a Database in MySQL “bca”
Step:2 Create a table “students”
Fields:
Id : INT : PRIMARY KEY
Sname: varchar(30)
City: varchar(30)
index.html
<html>
<head>
<title>Form</title>
</head>
<body>
<form action="InsertRec.php" method="post">
Name : <input type="text"
name="txtName"><br>
City : <input type="text"
name="txtCity"><br>
<input type="Submit" value = "Insert">
<input type="Reset" value ="Clear All">
</form>
</body>
</html>
InsertRec.php
<?php
$sname = trim($_POST["txtName"]);
$city = trim($_POST["txtCity"]);
if ($name === "")
{ // When No Name is Entered - It will not insert record
header("Location: index.html");
exit(); // Stop further execution
}
$con = mysqli_connect("localhost", "root", "", "bca");
$stmt = mysqli_query($con,"INSERT INTO students
(sname, city) VALUES ('$sname','$city')");
header("Location: DisplayRecords.php");
?>
DisplayRecords.php
<html>
<head>
<title>Form</title>
</head>
<body>
<table border="4">
<tr>
<th>Id</th>
<th>Name</th>
<th>City</th>
<th>Edit</th>
<th>Delete</th>
</tr>
<?php
$con = mysqli_connect(
"localhost",
"root",
"", "bca");
$qry = "SELECT * FROM students";
$s = mysqli_query($con, $qry);
while ($r = mysqli_fetch_row($s))
{
echo "<tr>";
echo "<td>".$r[0]."</td>";
echo"<td>".$r[1]."</td>";
echo "<td>".$r[2]."</td>";
echo "<td><a href='EditRecord.php?id=".
$r[0]."'>Edit</a></td>";
echo "<td><a
href='DeleteRecord.php?id=".
$r[0]."'>Delete</a></td>";
echo "</tr>";
}
echo "<tr>
<a href='index.html'>
Insert More Records
</a>
</tr>";
mysqli_close($con);
?>
</table>
</body>
</html>
DeleteRecord.php
(Here, SURAJ record is deleted)
<?php
$id = $_REQUEST["id"];
$con = mysqli_connect("localhost",
"root", "", "bca");
$stmt = mysqli_query($con,
"DELETE FROM students WHERE id = $id");
header("Location: DisplayRecords.php");
?>
EditRecord.php
<?php
$id = $_REQUEST["id"];
$con = mysqli_connect("localhost", "root", "", "bca");
$stmt =mysqli_query($con,
"SELECT * FROM students WHERE id = $id");
$rec = mysqli_fetch_array($stmt);
?>
<form action="Save.php" method="post">
<input type="hidden" name="id"
value="<?php echo $rec[0]; ?>"><br>
Name: <input type="text" name="txtName"
value="<?php echo $rec[1]; ?>"><br>
City: <input type="text" name="txtCity"
value="<?php echo $rec[2]; ?>"><br>
<input type="submit"> <input type="reset">
</form>
Save.php
<?php
$id = $_POST["id"];
$sname= $_POST["txtName"];
$city = $_POST["txtCity"];
$con = mysqli_connect("localhost",
"root", "", "bca");
$stmt = mysqli_query($con,
"UPDATE students
SET sname = '$sname',
city = '$city'
WHERE id = $id");
header("Location: DisplayRecords.php");
?>

More Related Content

Similar to "PHP and MySQL CRUD Operations for Student Management System" (20)

PDF
4.3 MySQL + PHP
Jalpesh Vasa
 
PPTX
Database Management - Lecture 4 - PHP and Mysql
Al-Mamun Sarkar
 
PPT
Database presentation
webhostingguy
 
PPTX
CHAPTER six DataBase Driven Websites.pptx
KelemAlebachew
 
PPTX
Php basics
Egerton University
 
PPT
Crash Course to SQL in PHP
webhostingguy
 
PPT
P H P Part I I, By Kian
phelios
 
ODP
Php modul-3
Kristophorus Hadiono
 
DOCX
Web Application PHP and MySQL Database
Sunny U Okoro
 
PPTX
Learn PHP Lacture2
ADARSH BHATT
 
DOCX
Php.docx
CHMuhammadZohaibZafa
 
PPSX
DIWE - Working with MySQL Databases
Rasan Samarasinghe
 
PPTX
PHP Database Programming Basics -- Northeast PHP
Dave Stokes
 
PPT
Migrating from PHP 4 to PHP 5
John Coggeshall
 
PPTX
7. PHP and gaghhgashgfsgajhfkhshfasMySQL.pptx
berihun18
 
PPTX
3 php-connect-to-my sql
Achchuthan Yogarajah
 
PPTX
Coding for php with mysql
Rajamanickam Gomathijayam
 
PPTX
Unit 4- Working with SQL.pptx
mythili213835
 
PPTX
UNIT V (5).pptx
DrDhivyaaCRAssistant
 
4.3 MySQL + PHP
Jalpesh Vasa
 
Database Management - Lecture 4 - PHP and Mysql
Al-Mamun Sarkar
 
Database presentation
webhostingguy
 
CHAPTER six DataBase Driven Websites.pptx
KelemAlebachew
 
Php basics
Egerton University
 
Crash Course to SQL in PHP
webhostingguy
 
P H P Part I I, By Kian
phelios
 
Web Application PHP and MySQL Database
Sunny U Okoro
 
Learn PHP Lacture2
ADARSH BHATT
 
DIWE - Working with MySQL Databases
Rasan Samarasinghe
 
PHP Database Programming Basics -- Northeast PHP
Dave Stokes
 
Migrating from PHP 4 to PHP 5
John Coggeshall
 
7. PHP and gaghhgashgfsgajhfkhshfasMySQL.pptx
berihun18
 
3 php-connect-to-my sql
Achchuthan Yogarajah
 
Coding for php with mysql
Rajamanickam Gomathijayam
 
Unit 4- Working with SQL.pptx
mythili213835
 
UNIT V (5).pptx
DrDhivyaaCRAssistant
 

More from Jainul Musani (20)

PDF
Core Java Interface Concepts for BCA Studetns
Jainul Musani
 
PDF
Java Abstract and Final Class for BCA students
Jainul Musani
 
PDF
Java Collection Framework for BCA Students
Jainul Musani
 
PDF
Simple Calculator using JavaFx a part of Advance Java
Jainul Musani
 
PDF
JavaFx Introduction, Basic JavaFx Architecture
Jainul Musani
 
PDF
ASP.NET 2010, WebServices Full Example for BCA Students
Jainul Musani
 
PDF
Palindrome Programme in PHP for BCA students
Jainul Musani
 
PDF
Leap Year Program in PHP for BCA students
Jainul Musani
 
PDF
Python: The Versatile Programming Language - Introduction
Jainul Musani
 
PPTX
Python a Versatile Programming Language - Introduction
Jainul Musani
 
PDF
React js t8 - inlinecss
Jainul Musani
 
PDF
React js t7 - forms-events
Jainul Musani
 
PDF
React js t6 -lifecycle
Jainul Musani
 
PDF
React js t5 - state
Jainul Musani
 
PDF
React js t4 - components
Jainul Musani
 
PDF
React js t3 - es6
Jainul Musani
 
PDF
React js t2 - jsx
Jainul Musani
 
PDF
React js t1 - introduction
Jainul Musani
 
PPTX
ExpressJs Session01
Jainul Musani
 
PPTX
NodeJs Session03
Jainul Musani
 
Core Java Interface Concepts for BCA Studetns
Jainul Musani
 
Java Abstract and Final Class for BCA students
Jainul Musani
 
Java Collection Framework for BCA Students
Jainul Musani
 
Simple Calculator using JavaFx a part of Advance Java
Jainul Musani
 
JavaFx Introduction, Basic JavaFx Architecture
Jainul Musani
 
ASP.NET 2010, WebServices Full Example for BCA Students
Jainul Musani
 
Palindrome Programme in PHP for BCA students
Jainul Musani
 
Leap Year Program in PHP for BCA students
Jainul Musani
 
Python: The Versatile Programming Language - Introduction
Jainul Musani
 
Python a Versatile Programming Language - Introduction
Jainul Musani
 
React js t8 - inlinecss
Jainul Musani
 
React js t7 - forms-events
Jainul Musani
 
React js t6 -lifecycle
Jainul Musani
 
React js t5 - state
Jainul Musani
 
React js t4 - components
Jainul Musani
 
React js t3 - es6
Jainul Musani
 
React js t2 - jsx
Jainul Musani
 
React js t1 - introduction
Jainul Musani
 
ExpressJs Session01
Jainul Musani
 
NodeJs Session03
Jainul Musani
 
Ad

Recently uploaded (20)

PPTX
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
PDF
Kit-Works Team Study_20250627_한달만에만든사내서비스키링(양다윗).pdf
Wonjun Hwang
 
PDF
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 
PDF
Go Concurrency Real-World Patterns, Pitfalls, and Playground Battles.pdf
Emily Achieng
 
PDF
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
PPTX
Seamless Tech Experiences Showcasing Cross-Platform App Design.pptx
presentifyai
 
PDF
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
PDF
UiPath DevConnect 2025: Agentic Automation Community User Group Meeting
DianaGray10
 
PDF
NLJUG Speaker academy 2025 - first session
Bert Jan Schrijver
 
PPTX
Digital Circuits, important subject in CS
contactparinay1
 
PPT
Ericsson LTE presentation SEMINAR 2010.ppt
npat3
 
PDF
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
PDF
Peak of Data & AI Encore AI-Enhanced Workflows for the Real World
Safe Software
 
PDF
UPDF - AI PDF Editor & Converter Key Features
DealFuel
 
PDF
“Squinting Vision Pipelines: Detecting and Correcting Errors in Vision Models...
Edge AI and Vision Alliance
 
PPTX
Future Tech Innovations 2025 – A TechLists Insight
TechLists
 
PPTX
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
PDF
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
PDF
“Computer Vision at Sea: Automated Fish Tracking for Sustainable Fishing,” a ...
Edge AI and Vision Alliance
 
PDF
LOOPS in C Programming Language - Technology
RishabhDwivedi43
 
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
Kit-Works Team Study_20250627_한달만에만든사내서비스키링(양다윗).pdf
Wonjun Hwang
 
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 
Go Concurrency Real-World Patterns, Pitfalls, and Playground Battles.pdf
Emily Achieng
 
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
Seamless Tech Experiences Showcasing Cross-Platform App Design.pptx
presentifyai
 
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
UiPath DevConnect 2025: Agentic Automation Community User Group Meeting
DianaGray10
 
NLJUG Speaker academy 2025 - first session
Bert Jan Schrijver
 
Digital Circuits, important subject in CS
contactparinay1
 
Ericsson LTE presentation SEMINAR 2010.ppt
npat3
 
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
Peak of Data & AI Encore AI-Enhanced Workflows for the Real World
Safe Software
 
UPDF - AI PDF Editor & Converter Key Features
DealFuel
 
“Squinting Vision Pipelines: Detecting and Correcting Errors in Vision Models...
Edge AI and Vision Alliance
 
Future Tech Innovations 2025 – A TechLists Insight
TechLists
 
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
“Computer Vision at Sea: Automated Fish Tracking for Sustainable Fishing,” a ...
Edge AI and Vision Alliance
 
LOOPS in C Programming Language - Technology
RishabhDwivedi43
 
Ad

"PHP and MySQL CRUD Operations for Student Management System"

  • 1. Step:1 Create a Database in MySQL “bca” Step:2 Create a table “students” Fields: Id : INT : PRIMARY KEY Sname: varchar(30) City: varchar(30)
  • 2. index.html <html> <head> <title>Form</title> </head> <body> <form action="InsertRec.php" method="post"> Name : <input type="text" name="txtName"><br> City : <input type="text" name="txtCity"><br> <input type="Submit" value = "Insert"> <input type="Reset" value ="Clear All"> </form> </body> </html> InsertRec.php <?php $sname = trim($_POST["txtName"]); $city = trim($_POST["txtCity"]); if ($name === "") { // When No Name is Entered - It will not insert record header("Location: index.html"); exit(); // Stop further execution } $con = mysqli_connect("localhost", "root", "", "bca");
  • 3. $stmt = mysqli_query($con,"INSERT INTO students (sname, city) VALUES ('$sname','$city')"); header("Location: DisplayRecords.php"); ?> DisplayRecords.php <html> <head> <title>Form</title> </head> <body> <table border="4"> <tr> <th>Id</th> <th>Name</th> <th>City</th> <th>Edit</th> <th>Delete</th> </tr> <?php $con = mysqli_connect( "localhost", "root", "", "bca"); $qry = "SELECT * FROM students"; $s = mysqli_query($con, $qry); while ($r = mysqli_fetch_row($s)) { echo "<tr>"; echo "<td>".$r[0]."</td>"; echo"<td>".$r[1]."</td>"; echo "<td>".$r[2]."</td>"; echo "<td><a href='EditRecord.php?id=". $r[0]."'>Edit</a></td>"; echo "<td><a href='DeleteRecord.php?id=".
  • 4. $r[0]."'>Delete</a></td>"; echo "</tr>"; } echo "<tr> <a href='index.html'> Insert More Records </a> </tr>"; mysqli_close($con); ?> </table> </body> </html> DeleteRecord.php (Here, SURAJ record is deleted) <?php $id = $_REQUEST["id"]; $con = mysqli_connect("localhost", "root", "", "bca"); $stmt = mysqli_query($con, "DELETE FROM students WHERE id = $id"); header("Location: DisplayRecords.php"); ?> EditRecord.php <?php $id = $_REQUEST["id"]; $con = mysqli_connect("localhost", "root", "", "bca"); $stmt =mysqli_query($con,
  • 5. "SELECT * FROM students WHERE id = $id"); $rec = mysqli_fetch_array($stmt); ?> <form action="Save.php" method="post"> <input type="hidden" name="id" value="<?php echo $rec[0]; ?>"><br> Name: <input type="text" name="txtName" value="<?php echo $rec[1]; ?>"><br> City: <input type="text" name="txtCity" value="<?php echo $rec[2]; ?>"><br> <input type="submit"> <input type="reset"> </form> Save.php <?php $id = $_POST["id"]; $sname= $_POST["txtName"]; $city = $_POST["txtCity"]; $con = mysqli_connect("localhost", "root", "", "bca"); $stmt = mysqli_query($con, "UPDATE students SET sname = '$sname', city = '$city' WHERE id = $id");