ok, pety te recuerdas que me dijiste que antes del html va el meto php entonces ese es mi problema que como estoy utilizando alertas si paso el método de registrar arriba del html no me llama las alertas, te anexo el código completo para que veas como lo implemento y el porque de mi pregunta si eso se puede hacer
Código PHP:
Ver original<!-- la session-->
<?php
if(!isset($_SESSION['fk_nivel'])) {
header('Location: ../index.php?Error=Acceso denegado'); echo "<script>alert('Disculpe Acceso registringido, Usuario no Autorizado')</script>";
}
?>
<!-- fin de la session-->
<!-- conexion y errores-->
<?php
include "../conexion/conexion.php";
?>
<!-- fin conexion y errores-->
<!-- proceso para registrar-->
<?php
echo '
<head>
<link rel="stylesheet" href="../css/sweetalert2.min.css">
<link rel="stylesheet" href="../css/sweetalert2.css">
<script src="../js/sweetalert2.js"></script>
<script src="../js/sweetalert2.min.js"></script>
</head>';
if(isset($_POST['guardar'])) {
$nombre = $_POST['nombre'];
$numero = $_POST['numero'];
$color = $_POST['color'];
$grupo = $_POST['grupo'];
$numero_letras = $_POST['numero_letras'];
$imgFile = $_FILES['portada']['name'];
$tmp_dir = $_FILES['portada']['tmp_name'];
$imgSize = $_FILES['portada']['size'];
$errMSG = "Por favor Ingrese el nombre.";
}
$errMSG = "Por favor Ingrese el numero.";
}
$errMSG = "Por favor Ingrese el color.";
}
$errMSG = "Por favor Indique el grupo al que pertenece.";
}
else if(empty($numero_letras)){ $errMSG = "Por favor Indique la cantidad de letras.";
}
else
{
$upload_dir = '../galerias_animalitos/'; // upload directory
// valid image extensions
$valid_extensions = array('jpeg', 'jpg', 'png', 'gif'); // valid extensions
// rename uploading image
$portada = rand(1000,1000000).".".$imgExt;
// allow valid image file formats
if(in_array($imgExt, $valid_extensions)){ // Check file size '5MB'
if($imgSize < 5000000) {
}
else{
echo "<script>
swal({
title: 'Ups Aviso...',
text: '¡ Lo siento, su archivo es demasiado grande !',
type: 'info',
showConfirmButton: false,
allowOutsideClick: false,
allowEscapeKey: false,
allowEnterKey: false,
});
</script>
<META HTTP-EQUIV='REFRESH' CONTENT=5;URL=http:registrar_animalitos.php>";
}
}
else{
echo "<script>
swal({
title: 'Ups Aviso...',
text: '¡ Lo sentimos, sólo se permiten archivos JPG, JPEG, PNG y GIF !',
type: 'info',
showConfirmButton: false,
allowOutsideClick: false,
allowEscapeKey: false,
allowEnterKey: false,
});
</script>
<META HTTP-EQUIV='REFRESH' CONTENT=5;URL=http:registrar_animalitos.php>";
}
}
// si no hay errores continuo...
$sql = $DB_con->prepare('INSERT INTO animalitos (nombre, numero, color, grupo, numero_letras, portada)
VALUES(:nombre, :numero, :color, :grupo, :numero_letras, :portada)');
$sql->bindParam(':nombre',$nombre);
$sql->bindParam(':numero',$numero);
$sql->bindParam(':color',$color);
$sql->bindParam(':grupo',$grupo);
$sql->bindParam(':numero_letras',$numero_letras);
$sql->bindParam(':portada',$portada);
if($sql->execute())
{
echo "<script>
swal({
title: 'Bien Hecho...',
text: '¡ Registro Insertado Correctamente !',
type: 'success',
showConfirmButton: false,
allowOutsideClick: false,
allowEscapeKey: false,
allowEnterKey: false,
});
</script>
<META HTTP-EQUIV='REFRESH' CONTENT=5;URL=http:registrar_animalitos.php>";
}
else
{
echo "<script>
swal({
title: 'Ups Aviso...',
text: '¡ Hubo un error al insertar el registro !',
type: 'info',
showConfirmButton: false,
allowOutsideClick: false,
allowEscapeKey: false,
allowEnterKey: false,
});
</script>
<META HTTP-EQUIV='REFRESH' CONTENT=5;URL=http:registrar_animalitos.php>";
}
}
?>
<!-- fin proceso para registrar-->
<!DOCTYPE html>
<html lang="es">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>cuál es el dato</title>
<link rel="icon" href="../mi favicon/cual es el dato.png">
<!-- CSS -->
<!-- Custom styles for this template -->
<link href="MDicons/css/MDicon.min.css" rel="stylesheet">
<link href="../css/list-inline-social.css" rel="stylesheet">
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<link href="../css/materialize.css" type="text/css" rel="stylesheet" media="screen,projection"/>
<link href="../css/hr.css" type="text/css" rel="stylesheet" media="screen,projection"/>
<link href="../css/style.css" type="text/css" rel="stylesheet" media="screen,projection"/>
</head>
<body>
<!-- menu-->
<?php
include 'menu.php';
?>
<!-- fin menu-->