Foros del Web » Programando para Internet » PHP »

Consulta Notice: Use of undefined constant operacion

Estas en el tema de Consulta Notice: Use of undefined constant operacion en el foro de PHP en Foros del Web. Muy buenas: No entiendo por qué en este código salen notice's: Notice: Use of undefined constant operacion - assumed 'operacion' in C:\xampp\htdocs\rentero\Ejercicio\index.php on line 20 ...
  #1 (permalink)  
Antiguo 12/09/2012, 04:23
 
Fecha de Ingreso: febrero-2011
Ubicación: Madrid
Mensajes: 9
Antigüedad: 13 años, 2 meses
Puntos: 0
Consulta Notice: Use of undefined constant operacion

Muy buenas:

No entiendo por qué en este código salen notice's:

Notice: Use of undefined constant operacion - assumed 'operacion' in C:\xampp\htdocs\rentero\Ejercicio\index.php on line 20

Notice: Undefined index: operacion in C:\xampp\htdocs\rentero\Ejercicio\index.php on line 20

Notice: Use of undefined constant nume - assumed 'nume' in C:\xampp\htdocs\rentero\Ejercicio\index.php on line 24

Notice: Undefined variable: operacion in C:\xampp\htdocs\rentero\Ejercicio\index.php on line 30

Notice: Undefined variable: operacion in C:\xampp\htdocs\rentero\Ejercicio\index.php on line 32
Listado de los trabajos

Notice: Undefined variable: operacion in C:\xampp\htdocs\rentero\Ejercicio\listado.php on line 17

Notice: Undefined variable: operacion in C:\xampp\htdocs\rentero\Ejercicio\listado.php on line 19

Notice: Undefined variable: operacion in C:\xampp\htdocs\rentero\Ejercicio\listado.php on line 21

Notice: Undefined variable: operacion in C:\xampp\htdocs\rentero\Ejercicio\listado.php on line 28

Notice: Undefined variable: operacion in C:\xampp\htdocs\rentero\Ejercicio\listado.php on line 28

Notice: Undefined variable: operacion in C:\xampp\htdocs\rentero\Ejercicio\listado.php on line 28

Os paso el código:

Código PHP:
<?php require("datos.php");?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="es">
<head>
    <title>Proyectos de empresa</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <link href="css/estilos.css" rel="stylesheet" type="text/css" />
</head>
<body>

<!-- CABECERA -->

<h1> <span id="pz">Empresa</span> <span id="shop" lang="en">Free</span><br/> <span id="lema">Proyectos de empresa</span> </h1>
<h2>Trabajadores</h2>


<?php 


    
if($_GET[operacion])
    
    {
$operacion$_GET[operacion];}
     
     if(!isset(
$_GET[nume])){
         
$nume="";
    }else{ 
        
$nume$_GET[nume];
    }

    if (
$operacion=='informes'){
    include(
'informes.php');
}else if (
$operacion=='informe1'){
    include(
'informe1.php');
}else{
    include(
'listado.php');
}
?>
</body>
</html>
  #2 (permalink)  
Antiguo 12/09/2012, 04:59
 
Fecha de Ingreso: mayo-2006
Mensajes: 475
Antigüedad: 17 años, 11 meses
Puntos: 58
Respuesta: Consulta Notice: Use of undefined constant operacion

En GET debes poner comillas o se da a entedender que lo que contiene es una constante
Código PHP:
Ver original
  1. <?php
  2.     if($_GET['operacion'])  
  3.     {$operacion= $_GET['operacion'];}    
  4.      if(!isset($_GET['nume'])){
  5.          $nume="";
  6.     }else{
  7.         $nume= $_GET['nume'];
  8.     }
  9.     if ($operacion=='informes'){
  10.     include('informes.php');
  11. }else if ($operacion=='informe1'){
  12.     include('informe1.php');
  13. }else{
  14.     include('listado.php');
  15. }
  16. ?>
  #3 (permalink)  
Antiguo 12/09/2012, 05:15
 
Fecha de Ingreso: febrero-2011
Ubicación: Madrid
Mensajes: 9
Antigüedad: 13 años, 2 meses
Puntos: 0
Respuesta: Consulta Notice: Use of undefined constant operacion

Lo siento pero he probado con comillas simples y dobles y siguen saliendo los notice
  #4 (permalink)  
Antiguo 12/09/2012, 05:29
 
Fecha de Ingreso: mayo-2006
Mensajes: 475
Antigüedad: 17 años, 11 meses
Puntos: 58
Respuesta: Consulta Notice: Use of undefined constant operacion

y cual es la linea 20?
  #5 (permalink)  
Antiguo 12/09/2012, 05:37
 
Fecha de Ingreso: febrero-2011
Ubicación: Madrid
Mensajes: 9
Antigüedad: 13 años, 2 meses
Puntos: 0
Respuesta: Consulta Notice: Use of undefined constant operacion

La línea 20 corresponde a:

if($_GET[operacion])
  #6 (permalink)  
Antiguo 12/09/2012, 05:54
 
Fecha de Ingreso: mayo-2006
Mensajes: 475
Antigüedad: 17 años, 11 meses
Puntos: 58
Respuesta: Consulta Notice: Use of undefined constant operacion

Claro, ese error te va a dar si no pasas ninguna variable GET, debes comprobar, al igual que haces con nume, si existe GET operacion.
Código PHP:
Ver original
  1. <?php
  2.     $operacion='';
  3.     $nume='';
  4.         if(isset($_GET['operacion'])){
  5.             $operacion= $_GET['operacion'];
  6.         }    
  7.          if(isset($_GET['nume'])){
  8.             $nume= $_GET['nume'];
  9.         }
  10.         if ($operacion=='informes'){
  11.             include('informes.php');
  12.         }elseif ($operacion=='informe1'){
  13.             include('informe1.php');
  14.         }else{
  15.             include('listado.php');
  16.         }
  17.     ?>

Etiquetas: constant, html, notice, operacion, undefined, variables
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 17:25.