Make an alert with php after a form

0

I am a newbie in programming, I recently made an "application" which saves some data in an input to a table in mysql and shows them on the page in the form of a table, by a form

<form action="enviar.php" method="post" autocomplete="off">
        <p><b>Fecha de Origen<br/><input type="text" name="FechaO" placeholder="Escriba la Fecha" required></input></b></p>
        <p><b>Materia<br/><input type="text" name="materia" placeholder="Escriba la Materia" required></input></b></p>
        <p><b>Descripcion<br/><input type="text" name="Descripcion" placeholder="Escriba la Descripcion" required></input></b></p>
        <p><b>Fecha de Entrega<br/><input type="text" name="FechaE" placeholder="Escriba la Fecha" required></input></b></p>
        <input type="submit"/>
        </form>
<?php
header("Location: Formulario.php");
include("php.php");
        if($_POST){
  $fecha1 = $_POST['FechaO'];
  $materia = $_POST['materia'];
  $descripcion = $_POST['Descripcion'];
  $fecha2 = $_POST['FechaE'];
 mysql_query("INSERT INTO tareas_t(Fecha_de_Origen,Materia,Descripcion,Fecha_de_Entrega)values('$fecha1','$materia','$descripcion','$fecha2')") or die(mysql_error());
 }

    ?>

but when I hit the send button, it redirected me to the page, then I put header ("Location: form.php"), and it works perfectly but I want it to send and send the data to the mysql table, this shows me an alert saying saved task, thanks for the help and the attention given.

    
asked by Kevin Rincon Moreno 25.03.2017 в 17:51
source

2 answers

1

you can do the following.

echo'<script type="text/javascript">
    alert("Tarea Guardada");
    window.location.href="index.php";
    </script>';

you put it at the end of your insert .

mysql_query("INSERT INTO tareas_t(Fecha_de_Origen,Materia,Descripcion,Fecha_de_Entrega)values('$fecha1','$materia','$descripcion','$fecha2')") or die(mysql_error());

echo'<script type="text/javascript">
        alert("Tarea Guardada");
        window.location.href="index.php";
        </script>';
    
answered by 25.03.2017 / 18:08
source
0

It's a possibility to use something more or less interactive like javascript, it's not difficult to implement, it's really been years since I've touched php, but I think the following code can help you, only you have to configure the path well of the file. js in the header tags. I think that php works in php. if it does not work, the only thing that should be done is to modify the type="submit" by "button".

<html>



<head>
     <script type="text/javascript" src="path donde estaría tu archivo ejemplo: /src/javascript.js"> </script>
</head>

<body>

<form action="enviar.php" method="post" autocomplete="off">
    <p><b>Fecha de Origen<br/><input type="text" name="FechaO" placeholder="Escriba la Fecha" required></input></b></p>
    <p><b>Materia<br/><input type="text" name="materia" placeholder="Escriba la Materia" required></input></b></p>
    <p><b>Descripcion<br/><input type="text" name="Descripcion" placeholder="Escriba la Descripcion" required></input></b></p>
    <p><b>Fecha de Entrega<br/><input type="text" name="FechaE" placeholder="Escriba la Fecha" required></input></b></p>
    <input type="submit" onclick="funcionAlerta()"/>
    </form>
<?php
header("Location: Formulario.php");
include("php.php");
    if($_POST){
  $fecha1 = $_POST['FechaO'];
  $materia = $_POST['materia'];
  $descripcion = $_POST['Descripcion'];
  $fecha2 = $_POST['FechaE'];
 mysql_query("INSERT INTO  tareas_t(Fecha_de_Origen,Materia,Descripcion,Fecha_de_Entrega)values('$fecha1','$materia','$descripcion','$fecha2')") or die(mysql_error());
 }

?>

</body>

</html>

And in the javascript.js file you create a more like function like this:

function funcionAlerta(){
alert("Los datos han sido enviados o lo que quieras");
}
    
answered by 25.03.2017 в 18:12