so I have a form and some php code to enter info in the database. However when i run the php file i get these errors:
Notice: Undefined index: first in C:\xampp\htdocs\temp\insert.php on line 24
Notice: Undefined index: last in C:\xampp\htdocs\temp\insert.php on line 25
Notice: Undefined index: email in C:\xampp\htdocs\temp\insert.php on line 26
Notice: Undefined index: message in C:\xampp\htdocs\temp\insert.php on line 27
Fatal error: Uncaught PDOException: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'first' cannot be null in C:\xampp\htdocs\temp\insert.php:29 Stack trace: #0 C:\xampp\htdocs\temp\insert.php(29): PDOStatement->execute() #1 {main} thrown in C:\xampp\htdocs\temp\insert.php on line 29
here is my html form:
<form action="insert.php" method="post">
    <label for="first" >Firstname:</label>
    <input type="text" name="first" id="first" />
    <label for="last" >Surname:</label>
    <input type="text" name="last" id="last" />
    <label for="email" >   Email: </label>
    <input type="text" name="email" id="email" />
    <label for="message">Message:</label>
    <textarea name="message" id="message"> Enter your question here and we will get back
    to you as soon as possible </textarea>
    <input type="Submit">
</form> 
and here is my php:
<?php
    $servername = "localhost";
    $username = "root";
    $password = "";
    $dbname = "test";
    try {
        $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
        $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
        echo "Connected successfully <br />";
    }
    catch(PDOException $e)
    {
        echo "Connection failed: " . $e->getMessage();
    }
    $query=$conn->prepare("INSERT INTO contacts (first, last, email, message) VALUES(?,?,?,?)");
    $query->bindParam(1, $first);
    $query->bindParam(2, $last);
    $query->bindParam(3, $email);
    $query->bindParam(4, $message);
    $first=$_POST['first'];
    $last=$_POST['last'];
    $email=$_POST['email'];
    $message=$_POST['message'];
    $query->execute();
    $conn = null;
    echo 'Hi '.$_POST['first'].' ' .$_POST['last'] .' thanks for your interest.</br>';
    echo 'We will contact you at '. $_POST['email'].' soon.</br>';
?>
 
     
    