Add, Create and Delete Button

Hi guys,

i have something to finish for my school :smiley:

I have a code who displays the data as table, from mysql database.

Now the only thing which is missing now is a delete button at the ned of the row, a edit button at the end of the row and a button at the end, to add new data.

I would be very glad and thankfull if you could help me (btw, english is not my native language)

Here is the code i have:

<?php

include('adminHeader.php');

// Below is optional, remove if you have already connected to your database.

$mysqli = mysqli_connect('localhost', 'root', '', 'firma');

// For extra protection these are the columns of which the user can sort by (in your database table).

$columns = array('person_id','name','vorname');

// Only get the column if it exists in the above columns array, if it doesn't exist the database table will be sorted by the first item in the columns array.

$column = isset($_GET['column']) && in_array($_GET['column'], $columns) ? $_GET['column'] : $columns[0];

// Get the sort order for the column, ascending or descending, default is ascending.

$sort_order = isset($_GET['order']) && strtolower($_GET['order']) == 'desc' ? 'DESC' : 'ASC';

// Get the result...

if ($result = $mysqli->query('SELECT * FROM mitarbeiter ORDER BY ' .  $column . ' ' . $sort_order)) {

    // Some variables we need for the table.

    $up_or_down = str_replace(array('ASC','DESC'), array('up','down'), $sort_order); 

    $asc_or_desc = $sort_order == 'ASC' ? 'desc' : 'asc';

    $add_class = ' class="highlight"';

    ?>

    <!DOCTYPE html>

    <html>

        <head>

            <title>PHP & MySQL Table Sorting by CodeShack</title>

            <meta charset="utf-8">

            <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.3.1/css/all.css" integrity="sha384-mzrmE5qonljUremFsqc01SB46JvROS7bZs3IO2EmfFsd15uHvIt+Y8vEf7N7fWAU" crossorigin="anonymous">

            <style>

            html {

                font-family: Tahoma, Geneva, sans-serif;

                padding: 10px;

            }

            table {

                border-collapse: collapse;

                width: 500px;

            }

            th {

                background-color: #54585d;

                border: 1px solid #54585d;

            }

            th:hover {

                background-color: #64686e;

            }

            th a {

                display: block;

                text-decoration:none;

                padding: 10px;

                color: #ffffff;

                font-weight: bold;

                font-size: 13px;

            }

            th a i {

                margin-left: 5px;

                color: rgba(255,255,255,0.4);

            }

            td {

                padding: 10px;

                color: #636363;

                border: 1px solid #dddfe1;

            }

            tr {

                background-color: #ffffff;

            }

            tr .highlight {

                background-color: #f9fafb;

            }

            </style>

        </head>

        <body>

        <h1>Mitarbeiterdaten</h1>

            <table>

                <tr>

                    <th><a href="adminMitarbeiterdaten.php?column=person_id&order=<?php echo $asc_or_desc; ?>">Mitarbeiter ID<i class="fas fa-sort<?php echo $column == 'person_id' ? '-' . $up_or_down : ''; ?>"></i></a></th>

                    <th><a href="adminMitarbeiterdaten.php?column=name&order=<?php echo $asc_or_desc; ?>">Name<i class="fas fa-sort<?php echo $column == 'name' ? '-' . $up_or_down : ''; ?>"></i></a></th>

                    <th><a href="adminMitarbeiterdaten.php?column=vorname&order=<?php echo $asc_or_desc; ?>">Vorname<i class="fas fa-sort<?php echo $column == 'vorname' ? '-' . $up_or_down : ''; ?>"></i></a></th>

                    <th><a href="adminMitarbeiterdaten.php?column=tel&order=<?php echo $asc_or_desc; ?>">Telefonnummer<i class="fas fa-sort<?php echo $column == 'tel' ? '-' . $up_or_down : ''; ?>"></i></a></th>

                    <th><a href="adminMitarbeiterdaten.php?column=email&order=<?php echo $asc_or_desc; ?>">Email<i class="fas fa-sort<?php echo $column == 'email' ? '-' . $up_or_down : ''; ?>"></i></a></th>

                    <th><a href="adminMitarbeiterdaten.php?column=stellung&order=<?php echo $asc_or_desc; ?>">Angestellt als<i class="fas fa-sort<?php echo $column == 'stellung' ? '-' . $up_or_down : ''; ?>"></i></a></th>

                </tr>

                <?php while ($row = $result->fetch_assoc()): ?>

                <tr>

                    <td<?php echo $column == 'person_id' ? $add_class : ''; ?>><?php echo $row['person_id']; ?></td>

                    <td<?php echo $column == 'name' ? $add_class : ''; ?>><?php echo $row['name']; ?></td>

                    <td<?php echo $column == 'vorname' ? $add_class : ''; ?>><?php echo $row['vorname']; ?></td>

                    <td<?php echo $column == 'tel' ? $add_class : ''; ?>><?php echo $row['tel']; ?></td>

                    <td<?php echo $column == 'email' ? $add_class : ''; ?>><?php echo $row['email']; ?></td>

                    <td<?php echo $column == 'stellung' ? $add_class : ''; ?>><?php echo $row['stellung']; ?></td>

                </tr>

                <?php endwhile; ?>

            </table>

        </body>

    </html>

    <?php

    $result->free();

}

?>

Programming is all about defining what goal you are trying to achieve, then designing, writing, testing, and debugging the code/query(ies) needed to accomplish that goal, researching along the way to find out things you don’t already know how to do.

Have you researched what the html markup would be for using a button in a href link? Have you defined what identifying data value you will include in the href link that you will use in the edit code to determine what row of data to query for to populate the form field values and use in the delete code to determine what row of data to delete? Have you defined what input data you will have, what processing you will do, and what result or output you will produce for each step? Have you researched what the sql query would be to select a single row of data (the edit page get request), update a single row of data (the edit page post method form processing), and delete a single row of data (the delete page post method form processing)?

Sponsor our Newsletter | Privacy Policy | Terms of Service