Welcome! Log In Create A New Profile

Advanced

[PHP] error Undefined index:

Posted by Romero, Fernando 
Romero, Fernando
[PHP] error Undefined index:
March 27, 2018 08:40PM
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
Jigar Dhulla
Re: [PHP] error Undefined index:
March 27, 2018 08:40PM
On Wed, Mar 28, 2018 at 12:04 AM, Romero, Fernando <
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://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
Christoph M. Becker
[PHP] Re: error Undefined index:
March 27, 2018 11:50PM
On 27.03.2018 at 20:34, Romero, Fernando wrote:

> <?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");

This looks like a potentially exploitable SQL injection vulnerability,
see http://www.php.net/manual/en/security.database.sql-injection.php.

--
Christoph M. Becker

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Romero, Fernando
RE: [PHP] error Undefined index:
March 28, 2018 12:50PM
De: Jigar Dhulla [mailto:[email protected]]
Enviado el: martes, 27 de marzo de 2018 3:38 p. m.
Para: Romero, Fernando <[email protected]>
CC: php-general@lists.php.net
Asunto: Re: [PHP] error Undefined index:



On Wed, Mar 28, 2018 at 12:04 AM, Romero, Fernando <[email protected]<mailto:[email protected]>> 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>
Tim Streater
[PHP] Re: error Undefined index:
March 28, 2018 01:20PM
On 28 Mar 2018, at 11:41, Fernando Romero <[email protected]> wrote:

> 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'];

It is undefined because in your <form> there is no element with the name 'impresa'.


--
Cheers -- Tim

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Jigar Dhulla
Re: [PHP] error Undefined index:
March 28, 2018 01:40PM
On Wed, Mar 28, 2018 at 4:11 PM, Romero, Fernando <
Fernando.Romero@trenesargentinos.gob.ar> wrote:

>
>
>
>
> *De:* Jigar Dhulla [mailto:[email protected]]
> *Enviado el:* martes, 27 de marzo de 2018 3:38 p. m.
> *Para:* Romero, Fernando <[email protected]>
> *CC:* php-general@lists.php.net
> *Asunto:* Re: [PHP] error Undefined index:
>
>
>
>
>
>
>
> On Wed, Mar 28, 2018 at 12:04 AM, Romero, Fernando <[email protected]
> 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://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>
>

​As Tim pointed out, there is no input element in your form which has
attribute "name​=empresa"


--
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
Romero, Fernando
RE: [PHP] error Undefined index:
March 28, 2018 03:40PM
-----Mensaje original-----
De: Jigar Dhulla [mailto:[email protected]]
Enviado el: miércoles, 28 de marzo de 2018 8:33 a. m.
Para: php-general@lists.php.net
Asunto: Re: [PHP] error Undefined index:

On Wed, Mar 28, 2018 at 4:11 PM, Romero, Fernando < Fernando.Romero@trenesargentinos.gob.ar> wrote:

>
>
>
>
> *De:* Jigar Dhulla [mailto:[email protected]] *Enviado el:*
> martes, 27 de marzo de 2018 3:38 p. m.
> *Para:* Romero, Fernando <[email protected]>
> *CC:* php-general@lists.php.net
> *Asunto:* Re: [PHP] error Undefined index:
>
>
>
>
>
>
>
> On Wed, Mar 28, 2018 at 12:04 AM, Romero, Fernando <[email protected]
> 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://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>
>

​As Tim pointed out, there is no input element in your form which has attribute "name​=empresa"


--
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

Thanks, solved
Alejandro Michelin Salomon
Re: [PHP] error Undefined index:
March 28, 2018 04:20PM
Hi.


Change FROM

$empresa = $_POST['empresa'];


TO

// To have a default value

$empresa = ( isset( $_POST['empresa'] ) ) ? $_POST['empresa'] : '';


Alejandro Michelin Salomon


________________________________
De: Romero, Fernando <[email protected]>
Enviado: quarta-feira, 28 de março de 2018 10:32
Para: Jigar Dhulla; php-general@lists.php.net
Assunto: RE: [PHP] error Undefined index:



-----Mensaje original-----
De: Jigar Dhulla [mailto:[email protected]]
Enviado el: miércoles, 28 de marzo de 2018 8:33 a. m.
Para: php-general@lists.php.net
Asunto: Re: [PHP] error Undefined index:

On Wed, Mar 28, 2018 at 4:11 PM, Romero, Fernando < Fernando.Romero@trenesargentinos.gob.ar> wrote:

>
>
>
>
> *De:* Jigar Dhulla [mailto:[email protected]] *Enviado el:*
> martes, 27 de marzo de 2018 3:38 p. m.
> *Para:* Romero, Fernando <[email protected]>
> *CC:* php-general@lists.php.net
> *Asunto:* Re: [PHP] error Undefined index:
>
>
>
>
>
>
>
> On Wed, Mar 28, 2018 at 12:04 AM, Romero, Fernando <[email protected]
> 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://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>
>

As Tim pointed out, there is no input element in your form which has attribute "name=empresa"


--
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

Thanks, solved
Richard
Re: [PHP] error Undefined index:
March 28, 2018 04:40PM
> Date: Wednesday, March 28, 2018 14:13:22 +0000
> From: Alejandro Michelin Salomon <[email protected]>
>
> Hi.
>
>
> Change FROM
>
> $empresa = $_POST['empresa'];
>
>
> TO
>
> // To have a default value
>
> $empresa = ( isset( $_POST['empresa'] ) ) ? $_POST['empresa'] : '';
>
>>
>> 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);
>>


Do not ignore that using a $_POST value, without sanitizing it first
is, as has been pointed out, a very serious sql injection
vulnerability vector. You might have fixed the "Undefined index"
issue, but this code (as previously presented) isn't something that
should be put into use.



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Romero, Fernando
RE: [PHP] error Undefined index:
March 28, 2018 05:20PM
-----Mensaje original-----
De: Richard [mailto:[email protected]]
Enviado el: miércoles, 28 de marzo de 2018 11:30 a. m.
Para: php-general@lists.php.net
Asunto: Re: [PHP] error Undefined index:



> Date: Wednesday, March 28, 2018 14:13:22 +0000
> From: Alejandro Michelin Salomon <[email protected]>
>
> Hi.
>
>
> Change FROM
>
> $empresa = $_POST['empresa'];
>
>
> TO
>
> // To have a default value
>
> $empresa = ( isset( $_POST['empresa'] ) ) ? $_POST['empresa'] : '';
>
>>
>> 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);
>>


Do not ignore that using a $_POST value, without sanitizing it first is, as has been pointed out, a very serious sql injection vulnerability vector. You might have fixed the "Undefined index"
issue, but this code (as previously presented) isn't something that should be put into use.



--
PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php

I solved it by adding the imput:

<select name = "empresa" onchange="fun_lista();">


Thank you all

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Sorry, only registered users may post in this forum.

Click here to login