RE: [PHP] error Undefined index:
| From: | Romero, Fernando | Date: | Wed, 28 Mar 2018 10:41:30 +0000 |
| Subject: | RE: [PHP] error Undefined index: | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-326421@lists.php.net to get a copy of this message | ||
De: Jigar Dhulla [mailto:jigar.tidus@gmail.com]
Enviado el: martes, 27 de marzo de 2018 3:38 p. m.
Para: Romero, Fernando <Fernando.Romero@trenesargentinos.gob.ar>
CC: php-general@lists.php.net
Asunto: Re: [PHP] error Undefined index:
On Wed, Mar 28, 2018 at 12:04 AM, Romero, Fernando <Fernando.Romero@trenesargentinos.gob.ar<mailto:Fernando.Romero@trenesargentinos.gob.ar>>
wrote:
I have an error with a variable in $ _POST that I can not find how to solve it
This is the error
Notice: Undefined index: empresa in /var/www/jobs/ganancia_por_empresa_mes.php on line 34
This is the query
<?php
$empresa = $_POST['empresa'];
$mes = $_POST['meses'];
$anio = $_POST['anio'];
if ( $_POST ) {
$result=pg_query("SELECT empresa, sum(valor) valor FROM trabajos WHERE
empresa='$empresa' and to_char(fecha, 'TMMONTH')::varchar = '$mes' and
date_part('year', fecha)= '$anio'
group by empresa");
$registros= pg_num_rows($result);
}
?>
<div align="center">
<table border="1" cellpadding="1">
<tr>
<td><strong>Empresa</strong></td>
<td><strong>Total</strong></td>
</tr>
<?php
//mostrar resultados
for ($i=0;$i<$registros;$i++)
{
$row = pg_fetch_array ($result,$i );
//}
?>
<tr>
<td>
<?php
echo $row['empresa'];
?>
</td>
<td>$
<?php
echo $row['valor'];
}
?>
</td>
</tr>
</table>
</div>
<div align="center" ><a
href="ganancia_empresa_mes.php">Volver</a></div>
</body>
</html>
The error of line 34 is this:
$empresa = $_POST['empresa'];
Thanks
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
what is the output of ?
var_dump( $_POST );
--
[https://thumbs.about.me/thumbnail/users/j/i/g/jigar_emailsig.jpg?_1518872123_201]<https://about.me/jigar?promo=email_sig&utm_source=product&utm_medium=email_sig&utm_campaign=edit_panel&utm_content=thumb>
Jigar Dhulla
about.me/jigar <https://about.me/jigar?promo=email_sig&utm_source=product&utm_medium=email_sig&utm_campaign=edit_panel&utm_content=thumb>
This is the file he calls
<body class="Azul">
<body style="background:#D3D3D3">
<p>
<body>
<form action="ganancia_por_empresa_mes.php" method="post">
<div align="center">
<select name = "lispart" onchange="fun_lista();">
<?php
$SQL="SELECT nombre FROM empresas";
$result = pg_query ($SQL ) or die("Error en la consulta SQL");
$registros= pg_num_rows($result);
while ($row = pg_fetch_assoc($result))
{
echo "<option
value='".$row['nombre']."'>".$row['nombre']."</option>";
}
?>
</select>
<select name="meses" id="meses">
<option value="ENERO">enero</option>
<option value="FEBRERO">febrero</option>
<option value="MARZO">marzo</option>
<option value="ABRIL">abril</option>
<option value="MAYO">mayo</option>
<option value="JUNIO">junio</option>
<option value="JULIO">julio</option>
<option value="AGOSTO">agosto</option>
<option value="SEPTIEMBRE">septiembre</option>
<option value="OCTUBRE">octubre</option>
<option value="NOVIEMBRE">noviembre</option>
<option value="DICIEMBRE">diciembre</option>
</select>
<select name="anio" id="anio">
<option value="2018">2018</option>
<option value="2019">2019</option>
<option value="2020">2020</option>
</select>
<input type="submit" name="envio" id="envio"
value="Enviar" />
</div></td>
</tr>
</div>
<label for="anio"></label>
<div align="center"></div>
</form>
<div align="center"><a
href="principal.php">Volver</a></div>
</body>
</html>