How can I insert the value from an (in a form) into a MySQL date field. I’m trying this:
<form action="enviar.php" autocomplete="off" method="post">
<label for="nacimiento" class="youpasswd" data-icon="p">
Fecha de Nacimiento
</label>
<br>
<input id="nacimiento" name="nacimiento"
required type="datetime" placeholder="DD/MM/YYYY" />
</form>
enviar.php
$nacimiento= $_POST['nacimiento'];
mysql_query("INSERT INTO voluntarios(nacimiento) VALUES ('$nacimiento')");`
This is working for all the other fields but not with the date field; it is empty. What am I doing wrong?
Thank you
You seem to have problems even getting the value from your
inputfield to the server. This needs to get fixed first. Debug (var_dump) your$_POSTdata and check what is going on. Provide more code if you need more help. From what you write, I don’t see, why the value shouldn’t get sent.After you got your date string, convert the value to a string literal format MySQL recognizes:
Then insert it using
mysqli_query:Using PDO do this: