Skip to main content

Insert,Update,Delete In One Page All the Operation In one Page in PHP

Insert,Update,Delete In One Page All the Operation In one Page in PHP


  • Here our Next topic is Insert,Update,delete Opration in one page.
  •  
  • Here i am going to create a php program which perform all this operation in one page.
  •  It is very simple and useful.
Let's start the program for it.

  • Open your favorite text editor and type following text.
 
 
<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>&nbsp;&nbsp;<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();
                }
     }

     }    
?>
 

Comments

  1. Goood Effort......I already had made this type of program for some other purposes...

    ReplyDelete
    Replies
    1. Nice but when you are commenting proper ways where start update query and delete query etc then your code very good for fresher

      Delete
  2. where is allinone.php main file is that one....

    ReplyDelete
  3. can you provide the link of this running code?? so can understand the frontend flow... please provide... reply as soon as possible..

    ReplyDelete
  4. Insert,Update,Delete In One Page All the Operation In one Page in PHP

    ReplyDelete
  5. Thanks for sharing this wonderful information. I too learn something new from your post..
    React JS Training in Chennai

    ReplyDelete
    Replies
    1. Above code is already outdated years ago... If you need backlinks tell me i will give you my other ranked article.

      Delete

Post a comment

Popular posts from this blog

13 VSCode Extensions That Every Web Developer Should Use

These are the most common extensions at VSCode that may be useful for you Almost every Web-Developer knows what VSCode is and why is it so important to use its extensions, they help us to debug our code, make it more readable and prettier, and just add more useful features to our workspace Of course, there’s not every useful extension, however, I have added 13 extensions without which I just can’t live. 1. Auto Close Tag It’s one of the most important extensions, As you may have noticed from the title, it automatically adds a close tag that you wanted to write. You don’t need any command to activate this extension 2. Auto Rename tag When you want to change your <button> tag to <a> you just will need to change the first(opening) tag and the second will change automatically 3. Beautify The function of it is straightforward— when you have an ugly file without any “spaces” and “tabs”, where every tag goes right after earlier, beautify will really help you To use this extension

8 VS Code Plugins To Improve Your Productivity

  VS Code is a great editor that ships with many features out of the box. That is one of the reasons why it’s the most used IDE. However, there are some areas where it can be improved — and that’s where extensions come into play. I’m not a big fan of having many plugins installed. There is always the risk of making your editor slower or introducing too much magic into your daily routine. You still need to be in the driver’s seat. That’s why I try to stay as close to the raw features as possible. I have no more than ten plugins installed at any given time. I try to be very tidy there. If you installed something and you feel it is not helping, just delete it. It might be distracting you or impacting performance. However, there are some very specific extensions that will have a very important impact on your productivity. I want to focus on those in this article. You are most likely not going to need them all, as your workflow might be different than mine, but you might discover something

5 Common CSS mistakes developers make

If you are starting your carrier as a web developer, CSS is a headache for many developers, based on my experience. It takes time to learn it and master it. This article is covering some common mistakes that you may face when writing CSS code. Ready, let’s go! 1. Using px when it’s not needed⁣   Do you know that you don’t need to use px when you want to set the a value to 0: 2. Repeating the same code⁣   Always keep in mind the DRY rule. Don’t repeat yourself. The number of code lines will cost you in terms of app performance and loading time. 3. Using color names⁣   Using a color code is better: 4. Not using shorthand properties⁣   Avoid multiline of code when you can do the same thing with one line: 5. No font fallback⁣ Always complete the font you’re using:   Read More :: 5 Common Challenges Faced by Web Developers   Read More :: Top 10 Web Development Trends for 2021