Insert, Update, Delete In One Page All the Operation In one Page in PHP
- Here is the Next topic is Insert, Update, delete Operation on one page.
- Here I am going to create a PHP program that performs all this operation in one page.
- It is very simple and useful.
Here is the example of insert update delete in php
- Open your favorite text editor and type the following text.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 | <form name="f1" method="post"> <?php $con=mysql_connect("localhost","root",""); mysql_select_db("login"); //database name $qu="select * from login"; //query to table $res=mysql_query($qu); echo '<table border=1><tr><td>Username</td> <td>Password</td><td>ACTION</td>'; while($row=mysql_fetch_array($res)) // Fetch data from table { if(isset($_GET['mode']))//GET the mode for operation like insert,uodate,delete { if($_GET['mode']=='upt'&& $_GET['id']==$row['username']) { echo '<tr><td><input type=text value='.$row['username'].' name=user></td>'; echo '<td><input type=text value='.$row['password'].' name=pass></td>'; echo '<td><input type=submit name=up value=Update></td>'; } if(isset($_POST['up'])) { $id=$_GET['id']; $user=$_POST['user']; $pass=$_POST['pass']; $qu="update login set username='$user',password='$pass' where username='$id'"; $res=mysql_query($qu); if(!$res) { echo mysql_query(); } } } else { echo '<tr><td>'.$row['username'].'</td>'; echo '<td>'.$row['password'].'</td>'; echo '<td><a href=allinone.php?mode=ins>Insert</a> <a href=allinone.php?mode=del&id='.$row['username'].'>Delete</a><a href=allinone.php?mode=upt&id='.$row['username'].'>Update</a></td>'; } } echo '<br>'; if(isset($_GET['mode'])) { if($_GET['mode']=='ins') { // echo '<form name=f1 action=allinone.php?mode='.$_GET['mode'].'>'; echo 'Username:<input type=text name=txtname>'; echo 'Password:<input type=text name=pass>'; echo '<input type=submit name=insert>'; } if(isset($_POST['insert'])) { $name=$_POST['txtname']; $pass=$_POST['pass']; $qu="insert into login values('$name','$pass')"; $res=mysql_query($qu); if(!$res) { echo mysql_error(); } } if($_GET['mode']=='del') { $id=$_GET['id']; $qu="delete from login where username='$id'"; $res=mysql_query($qu); if(!$res) { echo mysql_query(); } } } ?> |
Goood Effort......I already had made this type of program for some other purposes...
ReplyDeleteThanxxxxx
DeleteNice but when you are commenting proper ways where start update query and delete query etc then your code very good for fresher
Deletegood blog for php developer.
ReplyDeletewhere is allinone.php main file is that one....
ReplyDeletenice
ReplyDeletecan you provide the link of this running code?? so can understand the frontend flow... please provide... reply as soon as possible..
ReplyDeleteInsert,Update,Delete In One Page All the Operation In one Page in PHP
ReplyDeleteThanks for sharing this wonderful information. I too learn something new from your post..
ReplyDeleteReact JS Training in Chennai
Above code is already outdated years ago... If you need backlinks tell me i will give you my other ranked article.
Delete