In my oop php guestbook I sucssed to add the button delete but in sql database I wrote the function to delete the comment but I don't know hor can I add it to the comment and the comment be deleted

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

How to add the Delete Button 

I have task to create two guestbook , one with oop php and the second by sql database

In my oop php guestbook I sucssed to add the button delete but in sql database I wrote the function to delete the comment but I don't know hor can I add it to the comment and the comment be deleted 

Here in my oop code looks like the button and it shows in the picture. 

foreach($messageList as $key =>$obj){ 
    echo "<div class='div-containing-message'><h3>Posted by: " . $obj->getUsername() . "</h3><p>" . $obj->getMessage() . "</p><h4>Post's Date: " . $obj->getDateTime() . "</h4><br/><a class='guestbook-message-delete' href='part1.php?del=$key'>". "Delete</a></div><br/>";
    }

in my sql database 

delete function is in my Post.class.php: 

public function deletePost(int $id) {
        $sql = "DELETE FROM guestbook WHERE id=$id";
        return $this->db->query($sql);
    }

and my code of the sql guestbook is :

<?php $page_title = "Visitors's GuestBook"; ?>
    <?php include("includes/header.php"); ?>

    <?php include("includes/mainmenu.php"); ?>

    <article class="mainContent">

    <?php echo "<h1>$page_title</h1><br/>"; ?>

    <article class="guestbook-container">

    <div class="left-flexbox">

    <?php
    
    $db =  new mysqli(DBHOST, DBUSER, DBPASS, DBDATABASE);
    
        if($db->connect_errno > 0) {
        die("connection error: " . $db->connect_error);
    }

    if(isset($_POST['user'])) {
        $user = $_POST['user'];
        $content = $_POST['content'];
        $created = $_POST['created'];
       

        
        $sql = "INSERT INTO guestbook(user, content, created)VALUES('$user', '$content', NOW())";
        $result = $db->query($sql);
    }

    ?>

    <h3>Leave A Comment!</h3>

    <form action="part3.php" method="post">
    <label for="user">Your Name: </label>
    <input type="text" name="user" id="user">
    <br/>
    <br/>
    <label for="content"> Your Comment:</label>
    <textarea class="textrutan-message" name="content" id="content" rows="10" cols="30"></textarea>
    <br/><br/>
    <input type="submit" name="postMessage" value="Sumbit Your Post"><br/>
    </form>
    </div>

    <div class="right-flexbox">
    <?php

    // SQL-Question

    $sql = "SELECT * from guestbook /*ORDER BY created DESC*/";
    $result = $db->query($sql);
    while($row = $result->fetch_assoc()) {
        ?>
    
    <div class='div-containing-message'><h3> Posted By: <?= $row['user']; ?></h3>
    <p> <?= $row['content']; ?></p>
    <h4> Post's Date: <?= $row['created']; ?></h4>


    </div>


        <?php
    }
    ?>

 


    </div>

    </article>

     <?php include("includes/footer.php"); ?>

Vistors Company
Laboration 4
Part 1
Visitors's GuestBook
GuestBook
Part 2
GuestBookA
Leave A Comment!
GuestBookB
Your Name:
Posted by: VisirorA
JSON
It's a nice company
I recommended
Post's Date: 21:22 08-Mar-2022
Your Comment:
Delete
Submit Your Post
Show CSV-fil
Transcribed Image Text:Vistors Company Laboration 4 Part 1 Visitors's GuestBook GuestBook Part 2 GuestBookA Leave A Comment! GuestBookB Your Name: Posted by: VisirorA JSON It's a nice company I recommended Post's Date: 21:22 08-Mar-2022 Your Comment: Delete Submit Your Post Show CSV-fil
Vistors Company
Laboration 4
Part 1
Visitors's GuestBook
GuestBook
Part 2
GuestBookA
Leave A Comment!
GuestBookB
Your Name:
user
JSON
jij
2022-03-08 19:36:29
Your Comment:
Submit Your Post
Transcribed Image Text:Vistors Company Laboration 4 Part 1 Visitors's GuestBook GuestBook Part 2 GuestBookA Leave A Comment! GuestBookB Your Name: user JSON jij 2022-03-08 19:36:29 Your Comment: Submit Your Post
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY