<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
  require "../includes/db.php";

  $sql = "INSERT INTO children(ChildrenFirstName, ChildrenLastName, parentName, parentPhone, ChildrenDateOfBirth)
          VALUES ('" . mysqli_escape_string($conn, $_POST['ChildrenFirstName']) . "', '"
                      . mysqli_escape_string($conn, $_POST['ChildrenLastName']) . "', '"
                      . mysqli_escape_string($conn, $_POST['parentName']) . "', '"
                      . mysqli_escape_string($conn, $_POST['parentPhone']) . "', '"
                      . mysqli_escape_string($conn, $_POST['ChildrenDateOfBirth']) . "')";

  $results= mysqli_query($conn, $sql);

  if ($results === false) {
    echo mysqli_error($conn);
  } else {
    $id = mysqli_insert_id($conn);
    echo "Insert record with $id";
    echo $_POST['parentPhone'];

  }

}
 ?>
 
<section>
  <div class="field">
    <h2>Add New Children</h2>
  </div>

  <div class="field">
    <form  method="post">
      <div class="field">
        <label for="ChildrenFirstName"></label>
      Enter First Name : <input type="text" name="ChildrenFirstName" id="ChildrenFirstName">
      </div>

      <div class="field">
        <label for="ChildrenLastName"></label>
      Enter Last Name :<input type="text" name="ChildrenLastName" id="ChildrenLastName">
      </div>

      <div class="field">
        <label for="ChildrenDateOfBirth"></label>
      Date of Birth :<input type="date" name="ChildrenDateOfBirth" id="ChildrenDateOfBirth">
      </div>
      <hr>
      <p>Emergency Contact</p>
      <div class="field">
        <label for="Parent Name"></label>
      Parent Name :<input type="text" name="parentName" id="parentName">
      </div>
      <div class="field">
        <label for="parent Phone"></label>
      Phone Number :<input type="text" name="parentPhone" id="parentPhone">
      </div>
      <button> ADD </button>


    </form>
  </div>

  <!-- <a href="#" onClick="MyWindow=window.open('http://www.google.com','MyWindow','width=600,height=300'); return false;">Click Here</a> -->


</section>

