good afternoon
I have a problem, I am trying to save the data values from the form in the database.
AJAX is used to send the data using the POST method but when evaluating the outputs from the .done
and .fail
functions, they return no information.
This is the html
<div class="form">
<h1>Ingreso Alumno-Trabajo</h1>
<form name="formulario_contacto" id="formdata">
<p>
<label for="cest">cedula estudiante</label>
<input type="number" id="cest" name="cest" autofocus required>
</p>
<p>
<label for="nest">nombre estudiante</label>
<input type="text" id="nest" name="nest" required>
</p>
<p>
<label for="aest">Apellido estudiante</label>
<input type="text" id="aest" name="aest" required>
</p>
<p class="full-width">
<label for="tit">Titulo</label>
<textarea name="" id="tit" cols="30" rows="3" name="tit" required></textarea>
</p>
<p>
<label for="nase">nombre asesor</label>
<input type="text" id="nase" name="nase" required>
</p>
<p>
<label for="fsede">Sede :</label>
<select id="fSede" name="fSede">
<option value="Montalban">Montalban</option>
<option value="Guyana">Guayana</option>
<option value="Virtual">Virtual</option>
</select>
</p>
<p class="full-width button">
<input type="submit" value="Ingresar">
<input type="reset" value="Restaurar">
</p>
</form>
</div>
<div id="mensaje">
<h3></h3>
</div>
This is the JS using AJAX
<pre>
$(document).ready(function () {
// This part of the code will automatically execute when doc is ready.
$("#mensaje").html("");
$("input:submit").click(function () {
// We set the default action to be made once we submit.
// Let's validate the form first
if (validaForm()) {
var formulario = $("#formdata").serializeArray();
$.ajax({
// url: "php/enviar.php",
// type: "POST",
type: "POST",
url: "php/enviar.php",
dataType: "json",
data: formulario,
})
//do something when get response })
.done(function (respuesta) {
//do something when any erro
$("#mensaje").html(respuesta.mensaje);
alert("coño de la madre");
})
.fail(function (respuesta) {
//do something when any erro
alert("coño de la madre falla" + respuesta);
});
} else {
// We show this when the validation fails
$("#mensaje").html("falta Ingresar la data");
}
});
$("input:reset").click(function () {
$("#mensaje").html("");
});
});
</pre>
This is the PHP
<?php
echo "Estoy entrando aqui"; #I'm entering here
if(isset($_POST["cest"]))
{
$cedula = $_POST["cest"];
$nombre = $_POST["nest"];
$apellido = $_POST["aest"];
$titulo = $_POST["tit"];
$nomase = $_POST["nase"];
$sede = $_POST["fsede"];
$inserta = "INSERT INTO tbl-est-teg (cedula,nombre, apellido, titulo, nomase, sede) VALUES ('$cedula','$nombre','$apellido','$titulo','$nomase','$sede')";
$conexion = new mysqli("localhost","yguer2","s&4gBz6nPrA8*S7","estudiante-trabajo",3306);
$respuesta = new stdClass();
if($conexion->query($inserta)){
$respuesta->mensaje = "Se guardo correctamente";
}
else {
$respuesta->mensaje = "Ocurrió un error";
}
echo json_encode($respuesta);
}
?>