2

de que forma puedo implementar o reemplazar mis alert tradicionales al momento de guardar un registro, por sweet alert.

Mi formulario en html es el siguiente:

<h2>Agregar registro</h2>


<form action='procesar.php' method='post'>

Nro. Interno:
<input name="nro_inve" id="nro_inve" type="text">

<br>

Serial:
<input name="serial_inve" id="serial_inve" type="text">
<br>

Marca:
<select name="marca_inve">
      <option value="BRIDGESTONE">BRIDGESTONE</option>
      <option value="MICHELIN">MICHELIN</option>
      <option value="GOODYEAR">GOODYEAR</option>
</select>
<br>

Tamaño:
<input name="dimen_inve" id="serial_inve" type="text">
<br>

Diseño:
<input name="tipo_inve" id="serial_inve" type="text">

<br>

<input type="submit" name="submitcsv" value="GUARDAR"/>
</form>

Y luego al presionar e botón GUARDAR el va a procesar.php y si todo esta correcto dependiendo de la condición me muestra el mensaje en un alert.

require("conexion.php");
$conexion=conectar();


/* AQUÍ RECIBO LAS VARIABLES*/

$nro_inve=$_POST['nro_inve'];
$serial_inve=$_POST['serial_inve'];
$marca_inve=$_POST['marca_inve'];
$dimen_inve=$_POST['dimen_inve'];
$tipo_inve=$_POST['tipo_inve'];


$sql="insert into inventario(nro_inve,serial_inve,marca_inve,dimen_inve,tipo_inve)
values('$nro_inve','$serial_inve','$marca_inve','$dimen_inve','$tipo_inve')";

/* Y LUEGO ALLI ABAJO ESTAN LOS ALERT DEPENDIENDO DE LA CONDICIÓN ME MUESTRA
UN ALERT POSITIVO O NEGATIVO, ESTOS ALERT QUISIERA CAMBIARLOS POR SWEET ALERT
PARA QUE SE VEAN MÁS GRANDES Y MUCHO MEJOR */

$ok=mysql_query($sql,$conexion);
if ($ok)
    {
echo"<script type='text/javascript'>
        alert('El registro se realizo correctamente');
        window.location='balance.php';
        </script>";
    }
    else
    {
    echo "<script>alert('Error! intentalo nuevamente')
    window.location='balance.php';</script>";
    }

Como puedo hacer para cambiar esos alert por sweet alert para que se puedan ver más grandes y mucho mejor.

Muchísimas gracias.

Saludos.

1 respuesta 1

2

Necesitas descargar la librería para usar el sweetalert a tu proyecto e importarlo en tu pagina... o pon esto:

<script src="https://unpkg.com/sweetalert/dist/sweetalert.min.js"></script>

y en donde tengas un alert reemplazalo asi :

echo"<script type='text/javascript'>
        swal('El registro se realizo correctamente');
        window.location='balance.php';
        </script>";

y tendras algo asi :

<script src="https://unpkg.com/sweetalert/dist/sweetalert.min.js"></script>

<script> swal('El registro se realizo correctamente');  </script>

3
  • Buenas stre_leon aun no me funciona, hice lo que mencionaste y cuando guardo un registro solo se actualiza la pantalla no dice ningun mensaje solo inserta el registro y ya. ya no muestra los alert.
    – estrada
    el 18 oct. 2019 a las 12:34
  • Cuál de las dos opciones usaste ?... Descargar la librería o poner el link?! Sí fue la segunda considera que debes de tener internet...
    – streleon
    el 18 oct. 2019 a las 15:06
  • 1
    Listo ya me funciono, descargue la libreria y la ajuste a mi codigo, y listo funciona con o sin internet sin problemas. muchas gracias.
    – estrada
    el 22 oct. 2019 a las 14:02

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge you have read our privacy policy.

¿No es la respuesta que buscas? Examina otras preguntas con la etiqueta o formula tu propia pregunta.