Ver Mensaje Individual
  #1 (permalink)  
Antiguo 05/06/2018, 17:09
saulrayados
 
Fecha de Ingreso: abril-2016
Mensajes: 44
Antigüedad: 8 años
Puntos: 0
Error al mostrar mensaje

como puedo hacer para que si la pagina no existe me muestre un mensaje y si no hay conexion con la base de datos me muestre otro mensaje.
si le agrego el archivo funciones.php aparece el mensaje de que el servidor me reedirigio muchas veces

error.php
Código HTML:
Ver original
  1. <?php
  2.  
  3. require 'funciones.php';
  4. $id = isset($_GET['id']) ? (int)$_GET['id'] : false;
  5.  
  6. ?>
  7.  
  8.     <meta charset="UTF-8">
  9.     <meta name="viewport" content="width=device-width, user-scalable=no,
  10.     initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
  11. <link href="https://fonts.googleapis.com/css?family=Slabo+27px" rel="stylesheet">
  12. <link rel="stylesheet" href="css/estilos.css">
  13. </head>
  14.  
  15.     <?php if(!$id): ?>
  16.     <div style="font-size: 80px;
  17.                 text-align: center;
  18.                 position: relative;
  19.                 top: 35%;">
  20.     <p>Error 404 - Not found</p></font></center>
  21.     </div>
  22.     <div style="font-size: 23px;
  23.                 text-align: center;
  24.                 position: relative;
  25.                 top: 36%;">
  26.     <p>La página solicitada no existe</p>
  27.     </div>
  28.     <?php endif ?>
  29.  
  30.     <?php if(!$conexion): ?>
  31.     <div style="font-size: 80px;
  32.                 text-align: center;
  33.                 position: relative;
  34.                 top:35%;">
  35.         <p>Error 500<img src="images/error.png" width="10px" height="10px"></p>
  36.     </div>
  37.     <div style="font-size: 23px;
  38.                 text-align: center;
  39.                 position: relative;
  40.                 top:36%;">
  41.         <p>Hay un problema con el servidor, por favor intente mas tarde</p>
  42.     </div>-->
  43.     <?php endif ?>
  44.  
  45. </body>
  46. </html>

funciones.php
Código PHP:
Ver original
  1. <?php
  2.  
  3. function conexion($db, $usuario, $pass){
  4.     try {
  5.         $conexion = new PDO("mysql:host=localhost;dbname=$db", $usuario, $pass);
  6.         return $conexion;
  7.     } catch (PDOException $e) {
  8.         return false;
  9.     }
  10. }
  11.  
  12. $conexion = conexion('galeria', 'root', '');
  13.  
  14. if (!$conexion) {
  15.     header('error.php');
  16.     }
  17.  
  18. ?>

Última edición por saulrayados; 05/06/2018 a las 17:16