PHP - undefined variable

 
Vista:

undefined variable

Publicado por zendi (16 intervenciones) el 15/04/2010 18:19:19
estoy haciendo una pagina y cuando presiono EL boton de busqueda para desplegar unos registros me da el siguiente error: Notice: Undefined variable: articulo in /var/www/intranet/subsistemas/proveeduria/consultaporArticulo.php on line 75. No debiera traer nada ni siquiera el error este. Ademas la idea es NO traer EL CODIGO DE ARTICULO SI ESTA VACIO.
SI ALGUIEN PUDIERA AYUDARME

ESTE ES EL CODIGO COMPLETO:

<?php
require('../../recursos/inicio_sesion.php');
require('../../recursos/datos.php');
$datos=new CDatos('pg','localhost',$_SESSION['usuario'],$_SESSION['clave']);
if ($datos->ExisteError)
exit($datos->MsjCompleto);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<script language="JavaScript" src="calendario.js"></script>
<script language="JavaScript" src="overlib_mini.js"></script>
</head>
<style type="text/css">
.sr {
background-color: #FFFFCF;
color: #000000;
font-family: Arial;
font-size: 12px;
}
</style>
<body>
<!-- Colocar la fecha para que el usuario la escriba-->
<div id="overDiv" style="position:absolute; visibility:hidden; z-index:1000;"></div>
<form name="form1" action="consultaporArticulo.php" method="post"><fieldset style="width:auto"><LEGEND>Salidas por Artículos</LEGEND>
<TABLE align="center" class="div1">
<TR>
<td>Código del Artículo</td>
<td><input type="text" name="codart" size=10 maxlength=10></td>
</TR>
<tr>
<td><input TYPE="submit" NAME="buscar" VALUE="Buscar">
</TD>
</tr>
</TABLE>
</fieldset><br />
<table border='1' bordercolor='#00CC99' bgcolor='#99CC00'>
<tr class='sr'>
<th width='200'>Código
<th width='200'>Artículo
<th width='200'>Fecha
<th width='200'>Destino
<th width='200'>Despacahada
<th width='200'>Stock
</tr>
<?php
if (isset($_POST['codart']) && isset($_POST['buscar'])):
$codart = $_POST['codart'];
if ($datos->ExisteError)
exit($datos->MsjCompleto);
$kardexs=$datos->Registros('',"SELECT * FROM admon.v_kardex WHERE v_kardex.cod_articulo = '$codart' AND v_kardex.entrada = 'false'",'recurso');
endif;
while ($seleccionado =@pg_fetch_array($kardexs)):
$codigo = $seleccionado['cod_articulo'];
$articulo = $seleccionado['articulo'];
$fecha = $seleccionado['fecha2'];
$destino = $seleccionado['destino'];
$despachada = $seleccionado['despachada'];
$stock = $seleccionado['inv_proveeduria'];
$existencia = $seleccionado['existencia'];
echo"<table border='1' bordercolor='#00CC99' bgcolor='#99CC00'><tr>
<td width='200' align='center'style='font-size:13px;'>$codigo</td>
<td width='200' style='font-size:13px;'>$articulo</td>
<td width='200' align='center'style='font-size:13px;'>$fecha</td>
<td width='200' style='font-size:13px;'>$destino</td>
<td width='200' style='font-size:13px;'>$despachada</td>
<td width='200' style='font-size:13px;'>$stock</td>
</tr>
</table>";
endwhile;
echo "<table align='center'>
<tr>
<td bgcolor='#6699CC' style='font-size:13px;'>Total Existencia de $articulo</td>
<td width='100' bgcolor='#66CCFF' style='font-size:13px;'>$existencia</td>
</tr>
</table>";
?>
</form>
</body>
</html>
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

RE:undefined variable

Publicado por Diego Romero (14 intervenciones) el 15/04/2010 22:28:51
Es que si no entra al ciclo while, porque la consulta regresa un resultado vacío, igual trata de imprimir la variable $articulo la cual solo estaría definida si entra en el ciclo while.

Entonces lo que deberías hacer es una de dos cosas.

Definir la variable aunque no entre al ciclo while haciendo simplemente:

$articulo = '';

antes de ejecutarse el while, o bién...

Antes de ejecutar el while pregunta si la consulta SQL realmente devolvió registros usando la función pg_num_rows() con un if y pones todo lo que sigue dentro del if.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

RE:undefined variable

Publicado por zendi (16 intervenciones) el 16/04/2010 19:08:11
Diego disculpa tantas preguntas. ¿exactamente donde iria esa linea de codigo, ya que lo hice y no funciona?

este es el codigo:

<?php
require('../../recursos/inicio_sesion.php');
require('../../recursos/datos.php');
$datos=new CDatos('pg','localhost',$_SESSION['usuario'],$_SESSION['clave']);
if ($datos->ExisteError)
exit($datos->MsjCompleto);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<script language="JavaScript" src="calendario.js"></script>
<script language="JavaScript" src="overlib_mini.js"></script>
</head>
<style type="text/css">
.sr {
background-color: #FFFFCF;
color: #000000;
font-family: Arial;
font-size: 12px;
}
</style>
<body>
<!-- Colocar la fecha para que el usuario la escriba-->
<div id="overDiv" style="position:absolute; visibility:hidden; z-index:1000;"></div>
<form name="form1" action="consultaporArticulo.php" method="post"><fieldset style="width:auto"><LEGEND>Salidas por Artículos</LEGEND>
<TABLE align="center" class="div1">
<TR>
<td>Código del Artículo</td>
<td><input type="text" name="codart" size=10 maxlength=10></td>
</TR>
<tr>
<td><input TYPE="submit" NAME="buscar" VALUE="Buscar">
</TD>
</tr>
</TABLE>
</fieldset><br />
<table border='1' bordercolor='#00CC99' bgcolor='#99CC00'>
<tr class='sr'>
<th width='200'>Código
<th width='200'>Artículo
<th width='200'>Fecha
<th width='200'>Destino
<th width='200'>Despachada
<th width='200'>Stock
</tr>
<?php
if (isset($_POST['codart']) && isset($_POST['buscar'])):
$codart = $_POST['codart'];
if ($datos->ExisteError)
exit($datos->MsjCompleto);
$kardexs=$datos->Registros('',"SELECT * FROM admon.v_kardex WHERE v_kardex.cod_articulo = '$codart' AND v_kardex.entrada = 'false'",'recurso');
endif;
while ($seleccionado =@pg_fetch_array($kardexs)):
$codigo = $seleccionado['cod_articulo'];
$articulo = $seleccionado['articulo'];
$fecha = $seleccionado['fecha2'];
$destino = $seleccionado['destino'];
$despachada = $seleccionado['despachada'];
$stock = $seleccionado['inv_proveeduria'];
$existencia = $seleccionado['existencia'];
echo"<table border='1' bordercolor='#00CC99' bgcolor='#99CC00'><tr>
<td width='200' align='center'style='font-size:13px;'>$codigo</td>
<td width='200' style='font-size:13px;'>$articulo</td>
<td width='200' align='center'style='font-size:13px;'>$fecha</td>
<td width='200' style='font-size:13px;'>$destino</td>
<td width='200' style='font-size:13px;'>$despachada</td>
<td width='200' style='font-size:13px;'>$stock</td>
</tr>
</table>";
endwhile;
echo "<table align='center'>
<tr>
<td bgcolor='#6699CC' style='font-size:13px;'>Total Existencia de $articulo</td>
<td width='100' bgcolor='#66CCFF' style='font-size:13px;'>$existencia</td>
</tr>
</table>";
?>
</form>
</body>
</html>
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

RE:undefined variable

Publicado por Diego Romero (1450 intervenciones) el 18/04/2010 05:05:46
Como he dicho ya: antes del while.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

RE:undefined variable

Publicado por zendi (16 intervenciones) el 20/04/2010 20:31:56
Si, quedo muy bien gracias por tu ayuda.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar