SoftwareQuery
Home About Contact

How to Update Profile and delete in Php

 SoftwareQuery     19 comments   


Create the first index.php file
copy and paste this code

<?php
        include('update.php');
      if (isset($_GET['edit'])) {
        $id = $_GET['edit'];
        $update = true;
        $record = mysqli_query($db, "SELECT * FROM info WHERE id=$id");

        if (count($record) == 1 ) {
            $n = mysqli_fetch_array($record);
            $name = $n['name'];
            $address = $n['address'];
            $id = $n['id'];
        }
    }
?>
<!DOCTYPE html>
<html>
<head>
    <title>profile update page</title>
    </head>
<body>
<?php if (isset($_SESSION['message'])): ?>
    <div class="msg">
        <?php
            echo $_SESSION['message'];
            unset($_SESSION['message']);
        ?>
    </div>
<?php endif ?>

<table>
    <thead>
        <tr>
            <th>Name</th>
            <th>Address</th>
            <th colspan="2">Action</th>
        </tr>
    </thead>

    <?php while ($row = mysqli_fetch_array($results)) { ?>
        <tr>
            <td><?php echo $row['name']; ?></td>
            <td><?php echo $row['address']; ?></td>
            <td>
                <a class = "udatebutton" href="index.php?edit=<?php echo $row['id']; ?>" class="udatebutton" >Edit</a>
            </td>
            <td>
                <a class = "deletebutton" href="update.php?del=<?php echo $row['id']; ?>" class="deletebutton">Delete</a>
            </td>
        </tr>
    <?php } ?>
</table>
<form method="post" action="update.php" >
    <input type="hidden" name="id" value="<?php echo $id; ?>">
        <div class="input-group">
            <label>Name</label>
     <input type="text" name="name" value="<?php echo $name; ?>">
        </div>
        <div class="input-group">
            <label>Address</label>
      <input type="text" name="address" value="<?php echo $address; ?>"
        </div>
        <div class="input-group">

           <?php if ($update == true): ?>
    <button class="btn" type="submit" name="update" style="background: #556B2F;" >update</button>
<?php else: ?>
    <button class="btn" type="submit" name="save" >Save</button>
<?php endif ?>
</div>
    </form>
</body>
</html>
--------------------------------------------------------------------------------------------------------------
Create  style.css file
<style>

body {
    font-size: 19px;
}
table{
    width: 50%;
    margin: 30px auto;
    border-collapse: collapse;
    text-align: left;
}
tr {
    border-bottom: 1px solid #cbcbcb;
}
th, td{
    border: none;
    height: 30px;
    padding: 2px;
}
tr:hover {
    background: #ffff;
}

form {
    width: 45%;
    margin: 50px auto;
    text-align: left;
    padding: 20px;
    border: 1px solid #bbbbbb;
    border-radius: 5px;
}

.input-group {
    margin: 10px 0px 10px 0px;
}
.input-group label {
    display: block;
    text-align: left;
    margin: 3px;
}
.input-group input {
    height: 30px;
    width: 93%;
    padding: 5px 10px;
    font-size: 16px;
    border-radius: 5px;
    border: 1px solid gray;
}
updatebutton {
    padding: 10px;
    font-size: 15px;
    color: white;
    background: #5F9EA0;
    border: none;
    border-radius: 5px;
}
.editbutton {
    text-decoration: none;
    padding: 2px 5px;
    background: #2E8B57;
    color: white;
    border-radius: 3px;
}

.deletbutton{
    text-decoration: none;
    padding: 2px 5px;
    color: white;
    border-radius: 3px;
    background: #800000;
}
.msg {
    margin: 30px auto;
    padding: 10px;
    border-radius: 5px;
    color: #3c763d;
    background: #dff0d8;
    border: 1px solid #3c763d;
    width: 50%;
    text-align: center;
}
</style>

---------------------------------------------------------------------------------------------------------------
ADD This Code <head> tag in index.php
<link rel="stylesheet" type="text/css" href="addfilename">

----------------------------------------------------------------------------------------------------------------------
Create  update.php file

copy paste php code

<?php
session_start();
$db = mysqli_connect('localhost', 'root', '', 'crud');              // connection database code


$name = "";
$address = "";
$id = "0";
$update = false;

if (isset($_POST['save'])) {
$name = $_POST['name'];
$address = $_POST['address'];

mysqli_query($db, "INSERT INTO info (name, address) VALUES ('$name', '$address')");
$_SESSION['message'] = "Address saved";
header('location: index.php');
}

     if (isset($_POST['update']))
     {

$name  =  $_POST['name'];
$address = $_POST['address'];
$id  =  $_POST['id'];
$sql = "UPDATE info SET name='".$name."', address='".$address."' WHERE id='".$id."' ";
mysqli_query($db, $sql );
$_SESSION['message'] = "Address updated!";

header('location: index.php');

}
if (isset($_GET['del'])) {
$id = $_GET['del'];
mysqli_query($db, "DELETE FROM info WHERE id=$id");
$_SESSION['message'] = "Address deleted!";
header('location: index.php');         
 }
$results = mysqli_query($db, "SELECT * FROM info");


?>










  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg
Email ThisBlogThis!Share to TwitterShare to Facebook
Newer Post Older Post Home

19 comments:

  1. Anonymous12 April 2018 at 12:45

    Somebody necessarily help to make significantly posts
    I'd state. That is the first time I frequented your web page and up to now?
    I surprised with the research you made to make this actual publish extraordinary.
    Magnificent process!

    ReplyDelete
    Replies
      Reply
  2. Anonymous27 October 2018 at 21:42

    What's up i am kavin, its my first time to commenting
    anyplace, when i read this paragraph i thought i could also create comment due to this
    brilliant piece of writing.

    ReplyDelete
    Replies
      Reply
  3. Kamila23 February 2019 at 02:10

    Thank you for your post.
    Asp.Net Training in Chennai | Best Dot Net Training in Chennai
    Selenium Training in Chennai | Selenium Testing Training in Chennai
    Testing Courses in Chennai | Software Testing Course in Chennai
    Java Training Institute in Chennai | Core Java Training in Chennai | Java Course and Certification
    PHP Course in Chennai | PHP Training Institute in Chennai | PHP Course and Certification

    ReplyDelete
    Replies
      Reply
  4. Anonymous11 April 2019 at 11:59

    I visited various websites but the audio quality for audio songs current at this
    web page is in fact fabulous.

    ReplyDelete
    Replies
      Reply
  5. Anonymous13 April 2019 at 19:39

    Wow, marvelous blog layout! How long have you been blogging for?
    you make blogging look easy. The overall look of your website
    is excellent, as well as the content!

    ReplyDelete
    Replies
      Reply
  6. Anonymous15 April 2019 at 05:49

    My relatives always say that I am killing my time here at net,
    however I know I am getting experience daily by reading such pleasant articles or
    reviews.

    ReplyDelete
    Replies
      Reply
  7. Anonymous16 April 2019 at 09:35

    I was wondering if you ever considered changing the page layout of your site?
    Its very well written; I love what youve got to
    say. But maybe you could a little more in the way of content so people could connect with it better.

    Youve got an awful lot of text for only having one
    or 2 pictures. Maybe you could space it out better?

    ReplyDelete
    Replies
      Reply
  8. Anonymous17 April 2019 at 08:37

    Every weekend i used to go to see this web site,
    because i wish for enjoyment, as this this website conations genuinely fastidious funny material too.

    ReplyDelete
    Replies
      Reply
  9. Anonymous19 April 2019 at 22:54

    Simply want to say your article is as astonishing. The clarity in your post is simply
    spectacular and i can assume you are an expert on this subject.

    Well with your permission let me to grab your RSS feed to keep updated with forthcoming post.
    Thanks a million and please continue the gratifying work.

    ReplyDelete
    Replies
      Reply
  10. Anonymous21 April 2019 at 00:54

    We're a group of volunteers and opening a new scheme in our community.
    Your site offered us with valuable info to work
    on. You've done a formidable job and our whole community will be thankful to
    you.

    ReplyDelete
    Replies
      Reply
  11. Anonymous22 April 2019 at 09:14

    Link exchange is nothing else but it is just placing the other person's webpage link on your page at proper place and other person will also do same in support of you.

    ReplyDelete
    Replies
      Reply
  12. Anonymous23 April 2019 at 15:16

    Hey there would you mind letting me know which hosting company
    you're using? I've loaded your blog in 3 different browsers and I must say this blog loads
    a lot quicker then most. Can you recommend a good internet
    hosting provider at a honest price? Many thanks, I appreciate it!

    ReplyDelete
    Replies
      Reply
  13. Anonymous21 May 2019 at 04:04

    I like the valuable info you provide in your articles. I'll bookmark your blog and
    check again here frequently. I'm quite certain I'll learn many new stuff right here!
    Best of luck for the next!

    ReplyDelete
    Replies
      Reply
  14. Anonymous26 May 2019 at 10:33

    I know this if off topic but I'm looking into starting my own weblog and was wondering what all is
    required to get setup? I'm assuming having a blog like yours would cost a pretty penny?
    I'm not very internet savvy so I'm not 100% sure. Any recommendations or advice would be greatly appreciated.

    Kudos

    ReplyDelete
    Replies
      Reply
  15. Anonymous12 November 2019 at 13:14

    I do not even know how I ended up here, but I thought this post was great.
    I don't know who you are but certainly you're going to a famous blogger if you are not already
    ;) Cheers!

    ReplyDelete
    Replies
      Reply
  16. Anonymous16 November 2019 at 05:23

    Hello, i believe that i noticed you visited my website thus i got
    here to return the desire?.I am attempting to find issues to enhance my website!I guess its adequate to
    use some of your ideas!!

    ReplyDelete
    Replies
      Reply
  17. Anonymous20 November 2019 at 13:21

    An impressive share! I've just forwarded this onto a coworker who
    has been doing a little research on this. And he actually
    ordered me dinner simply because I stumbled upon it for
    him... lol. So allow me to reword this.... Thanks for the meal!!

    But yeah, thanx for spending some time to talk about this issue here on your website.

    ReplyDelete
    Replies
      Reply
  18. Anonymous21 November 2019 at 15:39

    Hello! This is kind of off topic but I need some help from
    an established blog. Is it hard to set up your own blog?
    I'm not very techincal but I can figure things out pretty fast.
    I'm thinking about creating my own but I'm not sure where to start.
    Do you have any points or suggestions? Appreciate it

    ReplyDelete
    Replies
      Reply
  19. Unknown21 September 2020 at 02:06

    Big data is a term that describes the large volume of data – both structured and unstructured – that inundates a business on a day-to-day basis. big data projects for students But it’s not the amount of data that’s important.Project Center in Chennai

    Spring Framework has already made serious inroads as an integrated technology stack for building user-facing applications. Corporate TRaining Spring Framework the authors explore the idea of using Java in Big Data platforms.

    Spring Training in Chennai

    The new Angular TRaining will lay the foundation you need to specialise in Single Page Application developer. Angular Training

    ReplyDelete
    Replies
      Reply
Add comment
Load more...

Donate

Translate

Popular Posts

  • How to Make Image Upload Code Using AJAX
    Direct Copy Paste PHP File  Image Upload Code -   <html> <head> <meta charset="utf-8"> <meta http-equi...
  • Best Useful Free Plugin to Make Wordpress Theme
    Meta Slider   - Meta Slider is that the initial free possibility on today’s list. A premium version is additionally obtainable...
  • How To Install Magento on Localhost XAMPP OR WAMP SERVER
      Step-1 => Make Sure you have to install Latest Version of  Xampp server or Wamp server in your PC.   Step -2 => Go to Web Bro...
  • How To Intall Node.js Via Command On Window And Linux.
    Step-1 . Firstly We have to go official website of https://nodejs.org/en/ then download the latest version of Nodejs zi...
  • How to Set up Amazon Affiliate Marketing Account to Earn Money
    Amazon Associates is a  marketing of Amazon company. It is allowed to youtube channel owner, Social Media pages owner and any type...
  • How To Create Custom Pagination In WordPress
    Hello, Friend's in this post we are creating a custom code of Pagination in WordPress. It is very easy to put this code any custom...
  • How to create facebook share and like button for webpage
    Step-1 . Go to web browser type google and write facebook sharing button click this URL or open this URL.                     Ref URL:...
  • How To Scrape Data From Website Url Using Php.
    Q. why using a Scraping. If we want to get data of another website then using web scraping. It is using a PHP HTML Dom parser library ...
  • How To Install Wordpress in Xampp Server And Wamp Server
      Step 1st  -      Install WampServer or Xampp Server.                                                                               ...
  • Upload Multiple Images to Firebase Storage with Angular
    Step-1 . Create a new Angular Project open command window then write a command.                     #ng new UploadImageApp Step-2 ....

Home

This blog Is very help full for beginner coder,if you want to learn new things definitely this Blog is very
helpful for you guys.

Followers

Contact form

Name

Email *

Message *

Blog

  • Home
  • About Us
  • Privacy Policy
  • Disclaimer
  • Contact Us
  • Terms&Conditions

NewsLetter

Copyright © SoftwareQuery | Powered by softwarequery
Design by ShubhamTiwari | Theme by softwarequery.com | Distributed By softwarequery/