Something is up with my code but I';m not sure what. I have created a very basic music library input form that saves to a mySQL table and outputs the data to the screen as well. For some reason it updates everytime I refresh my browser page and saves to the database. Can somebody tell me where I'm going wrong here? Thanks, Tim
<?php
    //connect
    $link = mysqli_connect("localhost", "my_username", "mypassword", "mydb");
    //create user feedback if library has been updated
    if(isset($_POST['submit'])) {
        $cleanartist = mysqli_real_escape_string($link, $_POST['Artist']);
        $cleantitle = mysqli_real_escape_string($link, $_POST['Title']);
        //create query statement
        $sql = "INSERT INTO albums (Artist, Title) VALUES ('$cleanartist', '$cleantitle')";
        //run query
        mysqli_query($link, $sql);
        echo "Thanks, added to library";
    }
    mysqli_close($link);
?>
<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>Music Library</title>
    </head>
    <body>
        <form class="" action="music_library.php" method="post">
            <p>Add Artist<input type="text" name="Artist"></p>
            <p>Album Title<input type"text" name="Title"></p>
            <input type="submit" name="submit" value="submit">
        </form>
        <?php
            //connect to db
            $link = mysqli_connect("localhost", "my_username", "mypassword", "mydb");
            //create query statement
            $qry = "SELECT * FROM albums";
            //run query and store result in variable
            $result = mysqli_query($link, $qry);
            //loop through returned data and output to screen
            while($row = mysqli_fetch_assoc($result)) {
                echo '<tr>';
                foreach($row as $field) {
                    echo '<td>' . $field . '</td>' . '</br>';
                }
            }
            mysqli_close($link);
        ?>
    </body>
</html>
 
     
     
    