I have a table that I am trying to INSERT INTO three different columns (child1Name, dobChild1, ageChild1) using a prepared statement. I can insert the data into this table within phpmyadmin utilizing the SQL tab. I have checked my connection and the formatting of the prepared statement and all appears correct.
I make it through the connection and the stmt prepare error check no problem and for all intents and purposes make it through the mysqli_stmt_bind_param and the mysqli_stmt_execute($stmt). This is where things get interesting, although I make it through each step of the prepared statement the data will not be entered into the database.
I believe this is because of the date formatting but not 100% sure.
The question I am asking is if I am making it through all of the prepared statement why won't my data push to the table? Everything looks like it should work to me.
include_once 'functions.inc.php';
session_start();
if (isset($_POST["submit"])) {
$child1Name = $_POST["child1Name"];
$dobChild1 = date('Y-m-d', strtotime($_POST['dobChild1']));
$ageChild1 = $_POST["ageChild1"];
$sql = "INSERT INTO children (child1Name, dobChild1, ageChild1) VALUES (?,?,?);";
$stmt = mysqli_stmt_init($conn);
if (!mysqli_stmt_prepare($stmt, $sql)) {
echo "SQL ERROR";
} else {
mysqli_stmt_bind_param($stmt, "ssi",
$child1Name, $dobChild1, $ageChild1);
mysqli_stmt_execute($stmt);
}
FORM
<form action="includes/mf2.inc.php" method="POST">
<div class="container text-center">
<div id="oneChild" class="childInfo d-none">
<div class="row">
<div class="col-md-3"></div>
<div class="col-md-2">
<label for="child1Name">
<span>1st Child Name:</span><br>
<input type="text" name="child1Name" class="child1Name" placeholder="John/Jane Doe"></input>
</label>
</div>
<div class="col-md-2">
<label for="DOB">
<span>Date of Birth</span><br>
<input type="date" name="dobChild1" class="dob"></input>
</label>
</div>
<div class="col-md-2">
<label for="ageChild1">
<span>age</span><br>
<input type="number" name="ageChild1" class="ageChild1" placeholder="99"></input>
</label>
</div>
</div>
<div class="submitButton">
<button type="submit" name="submit">Next</button>
</div>
</form>