Php Code for View, Search, Edit and Delete Record 2010
Code Example Page 1
P Ph hp p C Co od de e f fo or r V Vi ie ew w, , S Se ea ar rc ch h, , E Ed di it t a an nd d D De el le et te e R Re ec co or rd d f fr ro om m M My yS Sq ql l T Ta ab bl le e 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. 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"> </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>
Php Code for View, Search, Edit and Delete Record 2010
Code Example Page 2
Index.php (Snapshot) Student Database Search Enter Search Keyword
<? $search=$_POST["search"]; $flag=0; $query="select * from student where name like '%$search%' "; $result=mysql_query($query); while ($row = mysql_fetch_array($result)) { Php Code for View, Search, Edit and Delete Record 2010
</table> <? } ?> <p align="center"><a href="index.php">Go Back to Home</a></p> </body> </html>
Php Code for View, Search, Edit and Delete Record 2010
Code Example Page 5
View.php(Snapshots) Student Database VIEW STUDENT DATABASE Roll Number 1 Class 10 Name of Student Gunjan Kumar Father's Name Prem Shankar Sex Male Address1 Kankarbagh Address2 Lohia Nagar Address3
City Patna Phone 9334457195 Email [email protected] Remarks No remarks Go Back to Home
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"]; Php Code for View, Search, Edit and Delete Record 2010
Code Example Page 6
$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>";
<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> Add.php(Snapshots) Student Database ADD STUDENT RECORD Enter Roll Number
Enter Class
Enter Name of Student
Enter Father's Name
Sex Male Female Address1
Address2
Address3
City
Phone
Email
Remarks
ADD RECORD
Go Back to Home
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" /> Php Code for View, Search, Edit and Delete Record 2010
Php Code for View, Search, Edit and Delete Record 2010
Code Example Page 10
Edit.php(Snapshots) Student Database ADD STUDENT RECORD Enter Roll Number 3 Enter Class 10
Enter Name of Student Sonali Verm
Enter Father's Name Radhe Shya
Sex Male Female Address1
Address2
Address3
City Patna
Phone
Email sonali.chand
Remarks
UPDATE RECORD
Go Back to Home
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"); ?> Php Code for View, Search, Edit and Delete Record 2010
Code Example Page 11
</body> </html> You can also find this code from http://infozones.in/docs/ex1.rar Change the code as per your requirement
Visit http://infozones.in for Job(India) , Online GS Quiz and Online Reference Notes Know About Bihar from Bihar Directory Visit http://bihar.infozones.in
If you found any error or if you have any feedback regarding this code example mail me at [email protected]