<!doctype html>
<?php
    // attempt to connect to the DB
    $dbconn = mysqli_connect("localhost", "root", "", "madisonsmusicdatabaseofficial");
    if ($dbconn->connect_error > 0) {
        die('Could not connect: ' . $dbconn->connect_error);
        exit(); // you should redirect to some form of error page !!!!
    }
 
    $result = mysqli_query($dbconn, "SELECT * FROM ARTISTS");
    $datatable = "<table id='artiststable' class='table table-bordered table-striped' style='width:100%'>
            <thead>
            <tr>
                    <th></th>		
                    <th>ArtistName</th>
                    <th></th>
            </tr>
            </thead>
            <tbody>";
 
    while($row = mysqli_fetch_array($result))
       {
            $datatable.= "<tr>";
            $datatable.= "<td><a href=update.php?ArtistID=".$row['ArtistID'].">Edit</a></td>";
            $datatable.= "<td>" . $row['ArtistName'] . "</td>";
            $datatable.= "<td><a href=delete.php?ArtistID=".$row['ArtistID'].">Delete</a></td>";		
            $datatable.= "</tr>";
       }

    $datatable.= "</tbody></table>";

    //close connection
    mysqli_close($dbconn);
 ?>

<html lang="en">
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
        <meta name="description" content="">
        <meta name="author" content="Music Database">
        <meta name="generator" content="Jekyll v3.8.5">
        <title>Dashboard - Music Database</title>  

        <!-- include any relevant css/js files -->
        <?php include "../template/pageheader.php"; ?>

    </head>
    <body>
        <!-- include the top menu -->
        <?php include "../template/topmenu.php"; ?> 
        <!-- end top menu -->

        <div class="container-fluid">
            <div class="row">
                <!-- insert the side menu -->
                <?php include "../template/sidemenu.php"; ?>	
                <!-- end side menu -->

                <!-- webpage content goes here -->
                <main role="main" class="col-md-9 ml-sm-auto col-lg-10 px-4">
                  <div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom">
                        <h1 class="h1">Music Database</h1> 
                  </div>
                        <!-- display the list of customers -->
			<?php echo $datatable ?>
			<form action="post" method="get">
                            <input type="Submit" value="Display" onclick="form.action='index.php'"/>
                            <input type="Submit" value="Create" onclick="form.action='insert.php'"/>
			</form>                         
                </main>
            </div>
        </div>

        <!-- include any relevant js files -->
        <?php include "../template/pagefooter.php"; ?>

    </body>
</html>
