educratsweb logo


PHP (recursive acronym for "PHP: Hypertext Preprocessor") is a widely-used Open Source general-purpose scripting language that is especially suited for Web development and can be embedded into HTML.

This is the simple Code Example through which you can insert, Delete, View , Update from MySql Database.

 

Paste this code and save the file as written above. Create a database named test and create a table student as below structure.

 

MySql Table

 

CREATE TABLE `student` (  `roll` int(11) default NULL,  `class` varchar(20) default NULL,  `name` varchar(40) default NULL,  `f_name` varchar(40) default NULL,  `sex` varchar(6) default NULL,  `addr1` varchar(20) default NULL,  `addr2` varchar(20) default NULL,  `addr3` varchar(20) default NULL,  `city` varchar(20) default NULL,  `phone` varchar(12) default NULL,  `email` varchar(100)

default NULL,  `remarks` varchar(40) default NULL) ENGINE=InnoDB DEFAULT CHARSET=utf8;

 

 

Index.php [Main or Home Page]

 

 

<html>

<head>

<meta name="description" content="Php Code for View, Search, Edit and Delete Record" />

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<title>Search Student  Record</title>

</head>

<body>

<center><h1><u>Student Database</u></h1></center>

<form name="search" method="post" action="search.php">

<table style=" border:1px solid silver" cellpadding="10px" cellspacing="0px" align="center">

<tr>

<td colspan="3" style="background:#0066FF; color:#FFFFFF; font-size:20px">Search</td></tr>

<tr>

<td>Enter Search Keyword</td>

<td><input type="text" name="search" size="40" /></td>

<td><input type="submit" value="Search" /></td>

</tr>

<tr>

<td colspan="3">&nbsp;</td></tr>

<tr bgcolor="#CCCCCC">

<th><a href="add.php">Add Record</a></th>

<th><a href="del.php">Delete Record</a></th>

<th><a href="del.php">Update Record</a></th>

</tr>

</table>

</form>

</body>

</html>

 

 

 

Search.php

 

<?

mysql_connect("localhost");

mysql_select_db("test") or die("database could not connect ");

?>

<html>

<head>

<meta name="description" content="Php Code for View, Search, Edit and Delete Record" />

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<title>Search Student  Record</title>

</head>

<body>

<center><h1><u>Student Database</u></h1></center>

<form name="search" method="post" action="search.php">

<table style=" border:1px solid silver" cellpadding="5px" cellspacing="0px" align="center" border="0">

<tr>

<td colspan="3" style="background:#0066FF; color:#FFFFFF; font-size:20px">Search</td></tr>

<tr>

<td>Enter Search Keyword</td>

<td><input type="text" name="search" size="40" /></td>

<td><input type="submit" value="Search" /></td>

</tr>

<tr bgcolor="#666666" style="color:#FFFFFF">

<td>Roll & class</td>

<td>Name & Father's Name</td>

<td>&nbsp;</td>

 

<?

$search=$_POST["search"];

$flag=0;

$query="select * from student where  name like '%$search%' ";

$result=mysql_query($query);

while ($row = mysql_fetch_array($result)) {

$flag=1;

echo "<tr ><td>",$row[0],", ",$row[1],"</td><td><a href='view.php?roll=",$row[0],"'>",$row[2],", ",$row[3],"</a></td><td><a href='edit.php?roll=",$row[0],"'>Edit</a> | <a href='del.php?roll=",$row[0],"'>Delete</a></td></tr>";

 

}

if($flag==0)

echo "<tr><td colspan='3' align='center' style='color:red'>Record not found</td></tr>";

 

?>

<tr>

<td colspan="3">&nbsp;</td></tr>

<tr bgcolor="#CCCCCC">

<th colspan="3" align="right"><a href="add.php">Add Record</a></th>

</tr>

</table>

</form>

</body>

</html>

 

 

View.php

 

<?

mysql_connect("localhost");

mysql_select_db("test") or die("database could not connect ");

?>

<html>

<head>

<meta name="description" content="Php Code for View, Search, Edit and Delete Record" />

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<title>View Student  Record</title>

</head>

<body>

<center><h1><u>Student Database</u></h1></center>

<?

$roll=$_GET["roll"];

$query="select * from student where roll='$roll'";

$result=mysql_query($query);

while ($row = mysql_fetch_array($result)) {

 

?>

<table style=" border:1px solid silver" cellpadding="5px" cellspacing="0px" align="center" border="1">

<tr>

<td colspan="4" style="background:#0066FF; color:#FFFFFF; font-size:20px">VIEW STUDENT DATABASE</td></tr>

<tr>

<td> Roll Number</td><td><? echo $row[0];?></td>

<td> Class</td><td><? echo $row[1];?></td>

</tr>

<tr>

<td> Name of Student</td><td><? echo $row[2];?></td>

<td> Father's Name</td><td><? echo $row[3];?></td>

</tr>

<tr>

<td>Sex</td><td><? echo $row[4];?></td>

<td>Address1</td><td><? echo $row[5];?></td></tr>

<tr>

<td>Address2</td><td><? echo $row[6];?></td>

<td>Address3</td><td><? echo $row[7];?></td></tr>

<tr>

<td>City</td><td><? echo $row[8];?></td>

<td>Phone</td><td><? echo $row[9];?></td></tr>

<tr>

<td>Email</td><td><? echo $row[10];?></td>

<td>Remarks</td><td><? echo $row[11];?></td></tr>

<tr>

 

</table>

<?

}

?>

<p align="center"><a href="index.php">Go Back to Home</a></p>

</body>

</html>

 

 

 

Add.php

 

 

<?

mysql_connect("localhost");

mysql_select_db("test") or die("database could not connect ");

?>

<html>

<head>

<meta name="description" content="Php Code for View, Search, Edit and Delete Record" />

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<title>Add Student  Record</title>

</head>

<body>

<center>

  <h1><u>Student Database</u></h1>

</center>

<?

if($_POST["do"]=="store")

{

$roll=$_POST["roll"];

$class=$_POST["class"];

$name=$_POST["name"];

$fname=$_POST["fname"];

$sex=$_POST["sex"];

$addr1=$_POST["addr1"];

$addr2=$_POST["addr2"];

$addr3=$_POST["addr3"];

$city=$_POST["city"];

$phone=$_POST["phone"];

$email=$_POST["email"];

$remarks=$_POST["remarks"];

$query="insert into student value($roll,'$class','$name','$fname','$sex','$addr1','$addr2','$addr3','$city','$phone','$email','$remarks')";

mysql_query($query);

echo "<center>Successfully store in DATABASE</center>";

 

}

?>

<form name="add" method="post" action="add.php">

  <table style=" border:1px solid silver" cellpadding="5px" cellspacing="0px" align="center" border="0">

    <tr>

      <td colspan="4" style="background:#0066FF; color:#FFFFFF; font-size:20px">ADD STUDENT RECORD</td>

    </tr>

    <tr>

    <tr>

      <td>Enter Roll Number</td>

      <td><input type="text" name="roll" size="20"></td>

      <td>Enter Class</td>

      <td><input type="text" name="class" size="20"></td>

    </tr>

    <tr>

      <td>Enter Name of Student</td>

      <td><input type="text" name="name" size="20"></td>

      <td>Enter Father's Name</td>

      <td><input type="text" name="fname" size="20"></td>

    </tr>

    <tr>

      <td>Sex</td>

      <td><input type="radio" name="sex" value="Male">

        Male

        <input type="radio" name="sex" value="Female">

        Female </td>

      <td>Address1</td>

      <td><input type="text" name="addr1" size="20"></td>

    </tr>

    <tr>

      <td>Address2</td>

      <td><input type="text" name="addr2" size="20"></td>

      <td>Address3</td>

      <td><input type="text" name="addr3" size="20"></td>

    </tr>

    <tr>

      <td>City</td>

      <td><input type="text" name="city" size="20"></td>

      <td>Phone</td>

      <td><input type="text" name="phone" size="20"></td>

    </tr>

    <tr>

      <td>Email</td>

      <td><input type="text" name="email" size="20"></td>

      <td>Remarks</td>

      <td><input type="text" name="remarks" size="20"></td>

    </tr>

    <tr>

      <td colspan="4" align="center"><input type="hidden" name="do" value="store">

        <input type="submit" value="ADD RECORD"></td>

    </tr>

  </table>

</form>

<p align="center"><a href="index.php">Go Back to Home</a></p>

<?

include("search.php");?>

</body>

</html>

 

 

Edit.php

 

 

<?

mysql_connect("localhost");

mysql_select_db("test") or die("database could not connect ");

?>

<html>

<head>

<meta name="description" content="Php Code for View, Search, Edit and Delete Record" />

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<title>Update  Student  Record</title>

</head>

<body>

<?

if($_POST["do"]=="update")

{

$roll=$_POST["roll"];

$class=$_POST["class"];

$name=$_POST["name"];

$fname=$_POST["fname"];

$sex=$_POST["sex"];

$addr1=$_POST["addr1"];

$addr2=$_POST["addr2"];

$addr3=$_POST["addr3"];

$city=$_POST["city"];

$phone=$_POST["phone"];

$email=$_POST["email"];

$remarks=$_POST["remarks"];

$query="update student set name='$name',f_name='$fname',sex='$sex',addr1='$addr1',addr2='$addr2',addr3='$addr3',city='$city',phone='$phone',email='$email',remarks='$remarks' where roll=$roll";

mysql_query($query);

 

echo "<center>Successfully Updated in DATABASE</center>";

include("search.php");

 

}

?>

<center>

  <h1><u>Student Database</u></h1>

</center>

<?

$roll=$_GET["roll"];

$query="select * from student where roll='$roll'";

$result=mysql_query($query);

while ($row = mysql_fetch_array($result)) {

 

?>

<form name="update" method="post" action="edit.php">

  <table style=" border:1px solid silver" cellpadding="5px" cellspacing="0px" align="center" border="0">

    <tr>

      <td colspan="4" style="background:#0066FF; color:#FFFFFF; font-size:20px">ADD STUDENT RECORD</td>

    </tr>

    <tr>

    <tr>

      <td>Enter Roll Number</td>

      <td><? echo $row[0];?>

        <input type="hidden" name="roll" size="20" value="<? echo $row[0];?>"></td>

      <td>Enter Class</td>

      <td><input type="text" name="class" size="20" value="<? echo $row[1];?>" disabled="disabled"></td>

    </tr>

    <tr>

      <td>Enter Name of Student</td>

      <td><input type="text" name="name" size="20" value="<? echo $row[2];?>"></td>

      <td>Enter Father's Name</td>

      <td><input type="text" name="fname" size="20" value="<? echo $row[3];?>"></td>

    </tr>

    <tr>

      <td>Sex</td>

      <td><input type="radio" name="sex" value="Male" checked="checked">

        Male

        <input type="radio" name="sex" value="Female">

        Female </td>

      <td>Address1</td>

      <td><input type="text" name="addr1" size="20" value="<? echo $row[5];?>"></td>

    </tr>

    <tr>

      <td>Address2</td>

      <td><input type="text" name="addr2" size="20" value="<? echo $row[6];?>"></td>

      <td>Address3</td>

      <td><input type="text" name="addr3" size="20" value="<? echo $row[7];?>"></td>

    </tr>

    <tr>

      <td>City</td>

      <td><input type="text" name="city" size="20" value="<? echo $row[8];?>"></td>

      <td>Phone</td>

      <td><input type="text" name="phone" size="20" value="<? echo $row[9];?>"></td>

    </tr>

    <tr>

      <td>Email</td>

      <td><input type="text" name="email" size="20" value="<? echo $row[10];?>"></td>

      <td>Remarks</td>

      <td><input type="text" name="remarks" size="20" value="<? echo $row[11];?>"></td>

    </tr>

    <tr>

      <td colspan="4" align="center"><input type="hidden" name="do" value="update">

        <input type="submit" value="UPDATE RECORD"></td>

    </tr>

  </table>

</form>

<? } ?>

<p align="center"><a href="index.php">Go Back to Home</a></p>

</body>

</html>

 

 

 

Del.php

 

<?

mysql_connect("localhost");

mysql_select_db("test") or die("database could not connect ");

?>

<html>

<head>

<meta name="description" content="Php Code for View, Search, Edit and Delete Record" />

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<title>Add Student  Record</title>

</head>

<body>

<?

$roll=$_GET["roll"];

$query="delete from student where roll=$roll";

mysql_query($query);

echo "<center>Successfully Deleted</center>";

include("search.php");

?>

</body>

</html>

 

 

 

 

If you found any error or if you have any feedback regarding this code example mail me at gunjankumarverma@gmail.com

 

Php Code for View, Search, Edit and Delete Record from MySql Table
Contents shared By educratsweb.com

Health Care Tips फल के फायदे Fruit And Vegetable Benefits in hindi By #HelloKnowledge #Health - Published on Friday July 10 2020
if you have any information regarding Job, Study Material or any other information related to career. you can Post your article on our website. Click here to Register & Share your contents.
For Advertisment or any query email us at educratsweb@gmail.com

RELATED POST
1 Send E-mail to Multiple Person(E-mail) with Php
2 Php Code for View, Search, Edit and Delete Record from MySql Table
3 Know about Search Engine Optimization
4 गूगल फोन पर भारी डिस्काउंट
5 Php code example for Secure login
6 Php code for Online Quiz
7 9 Emerging Technologies to Lookout for in 2019
8 OPPO R17 PRO : फ़ास्ट चार्ज होगी बैटरी
9 HTML – Hyper Text Markup Language
10 Agricultural Technology Information Centre (ATIC)
11 Php code for Online Quiz
12 Php code for Comment on Webpage
13 BEST WAY TO COLLECT PAYMENTS ON YOUR WEBSITE
14 Php code example for login
15 Agricultural Technology Information Centre (ATIC)
16 Agricultural Technology Information Centre (ATIC)
17 Buy Redmi 6 Pro starts from Rs.10999
18 Top 20 Web Crawling Tools to Scrape the Websites Quickly
19 Top 15 Online Grocery Stores (Websites + Apps) in India
20 Google Translator Toolkit to be shut down on December 4, 2019
21 Send personalized email messages to your contacts with Mail Merge for Gmail
22 9 commands to check hard disk partitions and disk space on Linux
23 A To Z List of Linux Commands
24 AnyDesk Software
25 Top 5 Alternatives to the TikTok App
26 AarogyaSetu: A multi-dimensional bridge
27 Raksh is a 360-degree proximity detection device that senses other users within its proximity and sounds a warning as soon as another device comes within its defined range
28 Make a Free Website through Google Sites
29 Scientists observe celestial smash-up around nearby star
30 What is an API? (Application Programming Interface)
31 Computer based nano materials by INST Mohali can show the future of nano-electronics
32 Robust Digital Payment Infrastructure Enables Prompt Transfer of Cash Payment under Pradhan Mantri Garib Kalyan Package.
33 Union Agriculture Minister launches new features of e-NAM platform
34 DRDO develops bio suit with seam sealing glue to keep health professionals fighting COVID-19 safe
35 NIT Kurukshetra Implements Enterprises Resource Planning (ERP), SAMARTH
36 National Technology Day to be celebrated focusing on rebooting the economy through S&T
37 Ministry of MSME Launches CHAMPIONS Portal www.Champions.gov.in
38 The system has been certified for safety and performance by NABL accredited agencies and undergone stringent biomedical tests
39 How do I get a Digital Signature Certificate (DSC)?
40 Certifying Quantum Entanglement: A step towards Quantum Security
41 Aarogya Setu is now open source
42 Prime Minister pays tributes to scientists on the National Technology Day
43 To deal with COVID-19, CIPET to take up R&D initiatives in the areas of Health Care; manufacturing and Certifying PPE and other relevant products as per WHO/ ISO guidelines
44 MITRON APP | IS THIS AN ALTERNATIVE OF TIKTOK APP? MITRON APP VS TIKTOK APP.
45 Live telecast of the solar eclipse has been arranged via Zoom, YouTube and Facebook
46 Researchers find a new possibility to improve rice productivity
47 DST-SERB supports study for identification of structure-based potential antivirals against COVID 19
48 IT Minister Launches National AI Portal of India- www.ai.gov.in
49 Chinese hackers attempt over 40,000 cyber-attacks in 5 days on India: Maha Police
50 Detection of fluorine in hot Extreme Helium Stars solves their evolution mystery
We would love to hear your thoughts, concerns or problems with anything so we can improve our website educratsweb.com ! visit https://forms.gle/jDz4fFqXuvSfQmUC9 and submit your valuable feedback.
Save this page as PDF | Recommend to your Friends

http://educratsweb(dot)com http://educratsweb.com/content.php?id=53 http://educratsweb.com educratsweb.com educratsweb