我想将文本和日期等数据从HTML FORM插入PHP到MYSQL数据库

My code is already inserting a data on the database, but only the Primary key(AUTO_INCREMENT) is the only adding. I can't get the date and the text.

Is there something wrong in my code? Here is my code below:

HTML:

<form action="insertleave.php" method="post">
     <label>Date Filed:</label>
      <input type="date" name="datefiled">

      <label>Date of Leave:</label>
      <input type="date" name="leavedate">

  </div>
  <div class="medium-6 columns">
    <label>Reason of Leave:</label>
    <textarea rows="8" form="leaveform" name="reason"></textarea>
  </div>
  <input type="submit" class="expanded button" name="formSubmit" value="File Leave">
  </form>

PHP:

<?php
$datefiled = $_POST['datefiled'];
$leavedate = $_POST['leavedate'];
$leavereason = $_POST['leavereason'];

$config = parse_ini_file("phpconfig.ini");
$conn = mysqli_connect($config['host'], $config['username'], $config['password'], $config['dbname']);


if (!$conn) {
    die("Connection failed: " . mysqli_connect_error());
}


   $sql = "INSERT INTO leaves (ID, EmployeeID,DateFiled, LeaveDate, Reason)
   VALUES
   ('$ID','$EmployeeID','$DateFiled','$LeaveDate','$Reason')";


  if (mysqli_query($conn, $sql)) {
    echo "OK!";
} else {
    echo "Error: " . $sql . "<br>" . mysqli_error($conn);
}

mysqli_close($conn);
?>

In your text area, you given it a name "reason"

in your post variable, your value is "leavereason"

change the $leavereason = $_POST['leavereason']; to $leavereason = $_POST['reason'];

In you Reason of leave text area name of input is different.

Your variable name are different in your sql query and you are assigning to different variable.

Also your EmployeeID is empty here. there is no input for EmployeeID from html file or you should post it to php file.

Change you php code like this.

<?php
$datefiled = $_POST['datefiled'];
$leavedate = $_POST['leavedate'];
$leavereason = $_POST['reason'];

$config = parse_ini_file("phpconfig.ini");
$conn = mysqli_connect($config['host'], $config['username'], $config['password'], $config['dbname']);


if (!$conn) {
    die("Connection failed: " . mysqli_connect_error());
}


   $sql = "INSERT INTO leaves (ID, EmployeeID,DateFiled, LeaveDate, Reason)
   VALUES
   ('$ID','$EmployeeID','$datefiled','$leavedate','$leavereason')";


  if (mysqli_query($conn, $sql)) {
    echo "OK!";
} else {
    echo "Error: " . $sql . "<br>" . mysqli_error($conn);
}

mysqli_close($conn);
?>