How about, I have an ADD button, which contains two fields, which are filled and the data is sent to the table in mysql and in the table below
By clicking on SAVE to send the data I get this message, but I send it to another page, as I do to come out in the same modal window?
and I have to go back to the page and update so that the data appear, which is annoying, I want it to be done automatically, they told me that with ajax, but I do not know how, I just start and do not use it What do I need, a bookstore? I hope you can help me.
I leave my code for my modal
<!-- Modal-->
<form id="form1" name="form1" method="post" action="agregarModal_validacion.php">
<div id="myModal1" class="modal fade" role="dialog">
<div class="modal-dialog modal-sm">
<!-- Modal content-->
<div class="modal-content">
<!--Cabecera del modal-->
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Nuevo Trabajo</h4>
</div>
<!--Contenido del modal-->
<div class="modal-body">
<div class="form-group">
<div class="col-xm-6">
<input class="form-control" type="text" id="txt_nombre" name="txt_nombre" placeholder="Nombre del trabajo" required="">
</div>
</div>
<div class="form-group">
<div class="col-xm-6">
<input class="form-control " type="text" id="txt_costo" name="txt_costo" placeholder="Costo" required="">
</div>
</div>
</div>
<!--Final del modal-->
<div class="modal-footer">
<button type="submit" class="btn btn-success btn-lg" style="width: 100%;"><span class="glyphicon glyphicon-ok-sign"></span> Guardar</button>
</div>
</div>
</div>
</div>
</form>
And the code of my php that makes the query
<?
$conexion= mysqli_connect("localhost", "root", "root", "registros");
if($conexion)
{
//Variables
$Nombre_Trabajo = $_POST['txt_nombre'];
$Costo=$_POST['txt_costo'];
//realiza la consulta
$consulta= "INSERT INTO trabajos (Nombre_Trabajo, Costo) values ('$Nombre_Trabajo','$Costo')";
//para ejecutar consulta
$resultado=mysqli_query($conexion ,$consulta);
if ($resultado)
{
$messages[] = "Los datos han sido agregados correctamente";
}
else
{
$errors[]= "No se puedo realizar la accion";
}
if (isset($errors)){
?>
<div class="alert alert-danger" role="alert">
<button type="button" class="close" data-dismiss="consulta_lista.php">×</button>
<strong>Error!</strong>
<?php
foreach ($errors as $error) {
echo $error;
}
?>
</div>
<?php
}
if (isset($messages)){
?>
<div class="alert alert-success" role="alert">
<button type="button" class="close" data-dismiss="myModal1">×</button>
<strong>¡Bien hecho!</strong>
<?php
foreach ($messages as $message) {
echo $message;
}
?>
</div>
<?php
}
}
else{
echo "";
}
mysqli_close($conexion);
?>