Jump to content

Strange problem


wepnop

Recommended Posts

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.

 

Link to comment
Share on other sites

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"])) {

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.