I already have the solution, the failures were several.
In the HTML I did not have a form tag, which would fit me like this:
<form method="POST" id="form_fecha"><textarea id="seleccionar_fecha" name="seleccionar_fecha" hidden></textarea></form>
In the jQuery script I made some modifications:
old:
<script>
$(document).ready(function(){
$("body").on('click', '.dates li', function(){
var fecha = $("#form_fecha").serialize();
$("#seleccionar_fecha").text($(this).attr('id'));
setTimeout(function(){
$.ajax({
type:"POST",
url:"guardar_vacaciones.php",
success:function(i){
if (i==1) {
alert("correcto");
}else{
alert("error");
}
}
},1000);
});
});
updated:
<script>
$(document).ready(function(){
$("body").on('mouseenter', '.dates li', function() {
$("#seleccionar_fecha").text($(this).attr('id'));
});
$("body").on('click', '.dates li', function(){
var fecha = $("#form_fecha").serialize();
$.ajax({
type:"POST",
url:"guardar_vacaciones.php",
data:fecha,
success:function(i){
if (i==1) {
alert("enviado");
}else{
alert("error");
}
}
});
return false;
});
});
</script>
For which I added a return false
to not load the page when clicking on a box in the calendar and I also put a date variable that takes the name fields.
in PHP:
<?php
$conn = new mysqli("sql113.260mb.net","n260m_20445422","jyEsRoXZ","n260m_20445422_profesorado");
// Check connection
if (!$conn) {
die("Error: " . $conn->connect_error);
}
$fecha12= $_POST['seleccionar_fecha'];
$sql = " INSERT INTO vacaciones_pascua (fecha) VALUES ('$fecha12')";
echo mysqli_query($conn,$sql);
?>
First I did not put the table correctly, it was not 1esoacalendar but vacacion_pascua and at the end I have to print the mysqli_query ($ conn, $ sql), so that it prints 1 or 0, and the other, that is to say the POST was well called .
Finally it would look like this:
HTML:
<form method="POST" id="form_fecha"><textarea id="seleccionar_fecha" name="seleccionar_fecha" hidden></textarea></form>
jQuery:
<script>
$(document).ready(function(){
$("body").on('mouseenter', '.dates li', function() {
$("#seleccionar_fecha").text($(this).attr('id'));
});
$("body").on('click', '.dates li', function(){
var fecha = $("#form_fecha").serialize();
$.ajax({
type:"POST",
url:"guardar_vacaciones.php",
data:fecha,
success:function(i){
if (i==1) {
alert("enviado");
}else{
alert("error");
}
}
});
return false;
});
});
</script>
PHP:
<?php
$conn = new mysqli("sql113.260mb.net","n260m_20445422","jyEsRoXZ","n260m_20445422_profesorado");
// Check connection
if (!$conn) {
die("Error: " . $conn->connect_error);
}
$fecha12= $_POST['seleccionar_fecha'];
$sql = " INSERT INTO vacaciones_pascua (fecha) VALUES ('$fecha12')";
echo mysqli_query($conn,$sql);
?>
Thanks for your collaboration