guide to simple php do not delete [closed]

this is the get based api needed

if($_SERVER['REQUEST_METHOD'] === "GET" && count($_GET) == 0)
{
    require_once "connect.php";
    $connection = connect();
    $sql = "";
    $result=$connection->query($sql)->fetch_all(MYSQLI_ASSOC);
    $connection->close();
    header("Content-type: application/json; charset=utf-8");
    http_response_code(200);
    echo json_encode($result, JSON_UNESCAPED_UNICODE);
}
else
{
    http_response_code(400);
}
?>

connect.php:

<?php
function connect()
{
    return new mysqli("localhost","root","","palyazatok");
}
?>

php, aka the main site where the things are seen:


 <?php
            $url = "full path to api file";
            $sv = file_get_contents($url);
            echo $sv;
        ?>

if needed in table:

<?php
            $url = "full path to api file";
            $sv = file_get_contents($url);
            $data = json_decode($sv);
        ?>

        <table class="table">
            <thead>
                <tr>
                    <th></th>
                    <th></th>
                    <th></th>
                </tr>
            </thead>
            <tbody>
                <?php
                    foreach($data as $row)
                    {
                        echo '
                            <tr>
                                <td>'.$row->sql column (ex. id).'</td>
                                <td>'.$row->sql column (ex. id).'</td>
                                <td>'.$row->sql column (ex. id).'</td>
                            </tr>';
                    }
                ?>
            </tbody>
        </table>

some more details details details dw bout it I am adding details to it please I beg you let me post these are all the details needed

the api part: !!NEEDED LATER WITH ADDING NEW!!

   <?php
   if($_SERVER['REQUEST_METHOD'] === "GET" && count($_GET) == 1 && isset($_GET['id']) && (int) $_GET['id'] > 0)
   {
       $id = (int) $_GET['id'];
       require_once "connect.php";
       $connection = connect();
       $sql = "";
       $result = $connection->query($sql)->fetch_all(MYSQLI_ASSOC);
       $connection->close();
       header("Content-type: application/json; charset=utf-8");
       http_response_code(200);
       echo json_encode($result, JSON_UNESCAPED_UNICODE);
   }
   else
   {
       http_response_code(400);
   }
   ?>

here is the frontend part, the forms is the dropdown:

<?php
           $url = "entire path to api file";
           $sv = file_get_contents($url);
           $data = json_decode($sv);

           if(isset($_GET['id']) && trim($_GET['id']) !== "")
           {
               $id = (int) $_GET['id'];
               $url = "path to api?id=".$id;
               $sv = file_get_contents($url);
               $result = json_decode($sv);
           }
           else
           {
               $result = [];
           }
       ?>

       <form action="file.php" method="get">
           <select name="id" onchange="submit()">
               <option value="">--- choose ... ---</option>
               <?php
                   foreach($data as $d)
                   {
                       $s = isset($_GET['id']) && $_GET['id'] == $d->id ? "selected" : "";
                       $text = $d->id."sql fields you want to appear" ;
                       echo '<option value="'.$d->id.'" '.$s.'>'.$text.'</option>';
                   }
               ?>
           </select>
       </form>

       <?php
       if(count($result) == 0)
       {
           echo '<h3>womp</h3>';
           return;
       }
       ?>

       <table class="table table-bordered table-hover table-stripped table-success mt-3">
           <thead>
               <tr>
                   <th>Számlaszám</th>
                   <th>Dátum</th>
                   <th>Érték</th>
                   <th>Költség megnevezése</th>
               </tr>
           </thead>
           <tbody>
               <?php
                   foreach($result as $row)
                   {
                       echo '
                           <tr>
                               <td>'.$row->id.'</td>
                           </tr>
                       ';
                   }
               ?>
           </tbody>
       </table>

!$text = $d->id.”sql fields you want to appear” ;! in php adding values and string works with . so it will look like: $d->id.”Id “.name.” this data”; or smth like that the $s is referring to selected

deleting through api:

    <?php
if($_SERVER['REQUEST_METHOD'] === "POST" && count($_POST) == 1 && isset($_POST['id']) && (int) $_POST['id'] > 0)
{
    $id = (int) $_POST['id'];
    require_once "connect.php";
    $connection = connect();
    $sql = "DELETE FROM ... WHERE Id = '$id'";
    $result=$connection->query($sql)-> fetch_all(MYSQLI_ASSOC); ;
(if needed just repeat these two lines (if it needs to delete from multiple tables)
    $connection->close();
    header("Content-type: application/json; charset=utf-8");
    http_response_code(200);
    $result=[];
    echo json_encode($tomb, JSON_UNESCAPED_UNICODE);
}
else
{
    http_response_code(400);
}
?>

the php part to this:

<?php
        if ($_SERVER['REQUEST_METHOD'] === "POST" && isset($_POST['id']) && (int) $_POST['id'] > 0)
{
    $id = (int) $_POST['id'];
    $data = http_build_query(['id' => $id]);

    $context = stream_context_create([
        'http' => [
            'method'  => 'POST',
            'header'  => 'Content-type: application/x-www-form-urlencoded',
            'content' => $data
        ]
    ]);

    file_get_contents("full path again");

    header("Location: file.php", false, $context);
    exit;
}
    ?>

adding inserting into database (this is only one php file):

<?php
        if($_SERVER['REQUEST_METHOD'] === "POST" && isset($_POST['p_id'],$_POST['k_id'],$_POST['szszam'],$_POST['datum'],$_POST['ertek']))
        {
            $p_id = $_POST['p_id'];
            $k_id = $_POST['k_id'];
            $szszam = $_POST['szszam'];
            $datum = $_POST['datum'];
            $ertek = $_POST['ertek'];
            $sql = "INSERT INTO ... VALUES ('$szszam', '$datum', '$ertek', '$p_id', '$k_id')";
            require_once "connect.php";
            $kapcs = connect();
            $kapcs->query($sql);
            header("location:previous_file.php?id=$p_id");
            return;
        }
    ?>

        <?php
        //might need this multiple times
            $url = "api where it gave back json.php";
            $sv = file_get_contents($url);
            $data = json_decode($sv);
        ?>

        <form method="post" action="file.php">
            <select name="d_id" required>
                <option value="">--- choose ---</option>
                <?php
                    foreach($data as $d)
                    {
                        $txt = $d->id.' - '.......;
                        echo '<option value="'.$d->id.'">'.$txt.'</option>';
                    }
                ?>

body of the question, I do not need any more explaining, I can see through this just fine. please details details details details details