I have been trying to get data from my website to my MySQL table but everytime I try to insert data, my webpage shows undefined index. Any help would be appreciated.
<div class="form">
    <form action="legend.php" method="GET" id="legend">
        <h1>Contact Form</h1>          
        FIRST NAME<input type="text" id="fname" class="form-control" data-validation="length required " data-validation-length="min2" name="fname">        
        EMAIL<input type="email" id="email" class="form-control" data-validation="email required" name="email">     
        MESSAGE  <textarea class="form-control" name="message"  cols="50" data-validation= "message required" ></textarea>
        <input type="submit" class="btn btn-info" name="submit" value="Submit">
    </form>
    <?php
        if($_GET['submit']) {
            $id=$_GET['id'];
            $fname=$_GET['fname'];
            $email=$_GET['email'];
            if($fname!="" && $email!="") {
                $query = "INSERT INTO data(fname,email) VALUES('$fname','$email')";
                $data = mysqli_query($conn,$query);
            } else {
                echo "Enter all fields";
            }
        }
    ?>
</div>
At the top of the page I have given
<? include("connection.php"); ?>
and in the connection.php, i have given
<?php
    $servername= "localhost";
    $username= "root";
    $password= "";
    $dbname= "form";
    $conn= mysqli_connect($servername, $username, $password, $dbname);
    if($conn) { 
        echo"connected";
    } else {
        die("not connected because".mysqli_connected_error());
    }   
?>
Sorry for any noob mistake, I am new to web development.
 
     
     
    