wepnop Posted February 14, 2011 Share Posted February 14, 2011 Im installing and testing a web application, and im having a strange bug that annoyes me because it dint have any sense and also it dont affects really to the web functionality: if($_POST["eliminar"]==""){ $consulta='SELECT * FROM impressora where Activa=0'; $result=mysql_query($consulta,$conexion); echo"<table align=CENTER class='sample'>"; echo"<p align=center>LLISTA D'IMPRESSORES INACTIVES.</p>"; printf("<th>MODEL</th><th>MARCA </th>"); while($fila=mysql_fetch_array($result,MYSQL_ASSOC)){ echo"<tr>"; echo "<td>" . $fila["Model"] . "</td>"; echo "<td>" . $fila["Marca"] . "</td>"; echo"</td>"; if($_SESSION["admin"]!=0){ ?> <form method= "post" ACTION="impressores_inactives.php?idr=<?php echo($fila["Id_impressora"])?>"> <td colspan="2"><INPUT TYPE ="SUBMIT" NAME="eliminar" VALUE="Eliminar"></td> </form></td> <?php } echo "</tr>"; } echo"</table>"; }else{ echo 'eliminado'; echo $_POST["eliminar"]; //BORRAMOS DE LA BBDD LA IMPRESSORA $consulta="delete from impressora where Id_impressora='".$_GET["idr"] ."'"; $result=mysql_query($consulta); echo "<meta http-equiv=Refresh content=\" ; url=../Impressores/impressores_inactives.php\">"; } The problem is that php say that eliminar is undefinded, and if i test $_POST it says its empty. See that eliminar is the name of the submit post and its checked for a function that deletes a item. The problem is that script is actually working. I can delete the printer but with that error... and if i test the value of eliminar is always empty. Ask for any other explanation without a problem , the code is in spanish. Quote Link to comment Share on other sites More sharing options...
trq Posted February 14, 2011 Share Posted February 14, 2011 There is nothing strange about the warning. You are checking to see if a variable which may or may not be defined is empty. You should simply check for the variables existence. This..... if($_POST["eliminar"]==""){ should be.... if (!isset($_POST["eliminar"])) { Quote Link to comment Share on other sites More sharing options...
silkfire Posted February 14, 2011 Share Posted February 14, 2011 You always have to check whether $_POST variables are set before you access them. if (isset($_POST['eliminar']) && empty($_POST['eliminar'])) {...} Quote Link to comment Share on other sites More sharing options...
wepnop Posted February 14, 2011 Author Share Posted February 14, 2011 I know that but it isnt my code. Well, the problem is that the warning is showing up wether i have stayed in the page the first time so the variable is undefined or im removing a items (so it have a value) Also way also call empty? Quote Link to comment Share on other sites More sharing options...
silkfire Posted February 14, 2011 Share Posted February 14, 2011 empty() is the same as doing == "" check. What do you mean it's not your code? Quote Link to comment Share on other sites More sharing options...
wepnop Posted February 14, 2011 Author Share Posted February 14, 2011 empty() is the same as doing == "" check. What do you mean it's not your code? I mean that its other people code and im just testing it. Quote Link to comment Share on other sites More sharing options...
wepnop Posted February 14, 2011 Author Share Posted February 14, 2011 skillfire if i put your code in place of that it beggins a eternal loop, wtf, whats going on? Quote Link to comment Share on other sites More sharing options...
wepnop Posted February 14, 2011 Author Share Posted February 14, 2011 Well, i erased all the content and tested well and i get whats going wrong: the erase item option refreshes the page. The problem is that php thinks that the eliminar value is passed always so it try to erase always, creating the bucle. Quote Link to comment Share on other sites More sharing options...
wepnop Posted February 14, 2011 Author Share Posted February 14, 2011 I resolved it, or well, thats what i think. <?php include("../cabecera.php"); if(!isset($_SESSION["admin"])){ ?><script>alert('NO TENS ACCÉS A AQUESTA SECCIÓ.')</script><?php echo "<meta http-equiv=Refresh content=\" ; url=../Login/login.php\">"; exit(); } include ("../Menu/menu.php"); # La accion de eliminar se va a ejecutar solo si el eliminar se ha pasado if (isset($_POST['eliminar'])) { # Ejecuta la opcion de eliminar si se ha pasado algun valor if (!empty($_POST['eliminar']) ) { echo 'elm'; //BORRAMOS DE LA BBDD LA IMPRESSORA $consulta="delete from impressora where Id_impressora='".$_GET["idr"] ."'"; $result=mysql_query($consulta); echo "<meta http-equiv=Refresh content=\" ; url=../Impressores/impressores_inactives.php\">"; } # Si no se ha pasado ningun valor se imprime el formulario para dar las opciones } else { echo 'va'; $consulta='SELECT * FROM impressora where Activa=0'; $result=mysql_query($consulta,$conexion); echo"<table align=CENTER class='sample'>"; echo"<p align=center>LLISTA D'IMPRESSORES INACTIVES.</p>"; printf("<th>MODEL</th><th>MARCA </th>"); while($fila=mysql_fetch_array($result,MYSQL_ASSOC)){ echo"<tr>"; echo "<td>" . $fila["Model"] . "</td>"; echo "<td>" . $fila["Marca"] . "</td>"; echo"</td>"; if($_SESSION["admin"]!=0){ ?> <form method= "post" ACTION="impressores_inactives.php?idr=<?php echo($fila["Id_impressora"])?>"> <td colspan="2"><INPUT TYPE ="SUBMIT" NAME="eliminar" VALUE="Eliminar"></td> </form></td> <?php } echo "</tr>"; } echo"</table>"; } include"../pie.php"; ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.