Foros del Web » Programando para Internet » PHP »

variable indefinida con checkbox

Estas en el tema de variable indefinida con checkbox en el foro de PHP en Foros del Web. hola chicos espero que esten bien neceisto otra vez algo de ayuda he hecho un correo en mi pagina y utilizo los checkbox estilo hotmail ...
  #1 (permalink)  
Antiguo 02/10/2009, 15:09
Avatar de towel  
Fecha de Ingreso: marzo-2009
Mensajes: 101
Antigüedad: 15 años, 1 mes
Puntos: 0
variable indefinida con checkbox

hola chicos espero que esten bien neceisto otra vez algo de ayuda he hecho
un correo en mi pagina y utilizo los checkbox estilo hotmail ahora eso esta bien el elimina los mensaje bien, ahora los mensajes los muestro con td oculto cuando el
mensaje esta havierto y lo deseo eliminar no me sirve me manda una variable indefinida me podrian ayudar aqui les dejo el codigo
codigo php
Código:
<?php
include('../funciones/error.php');
include('../funciones/funciones.php');
include('../funciones/class_conexion.php');
include('../funciones/paginator.php');
include('../funciones/paginator_html.php');
$BD = new class_conexion();
valida_session();
/*foreach ($_POST as $c => $v){
echo $c." = ".$v."<br>";
}*/
$page = 1;
$idusuarioS = $_SESSION['idusuarioS'];

$pag = "SELECT id_mail,id_usuario,id_usuarioS
		FROM usuarios_mensajes_mail
		WHERE id_usuario = '".$idusuarioS."'";
		$rpag = $BD->ejecutar_sql($pag);
        $nreg = $BD->num_rows($rpag);
		//echo "pag = ".$pag."<br>";
if($nreg > 0)
{
	$Registros = 15;
	$funcion = "mail_mail_ver";
	$a = & new Paginator_ajax($page, $nreg, $funcion);
	$a->set_Limit($Registros);//numero de registros por pagina
	$a->set_Links(3);
	
	//=Punto de partida de la Paginacion
	$limit1 = $a->getRange1(); 
	//=Numero de items que se despliegan en pantalla
	$limit2 = $a->getRange2();

		
$sql = "SELECT id_mail,id_usuario,id_usuarioS, mensaje_mail, fhingreso, newslastter, revizado_mail,
        (SELECT nombre_usuario FROM usuarios WHERE usuarios_mensajes_mail.id_usuarioS = usuarios.id_usuario ) AS nom_usuario
		FROM usuarios_mensajes_mail
		WHERE id_usuario = '".$idusuarioS."'
		ORDER BY fhingreso DESC 
		LIMIT ".$limit2." OFFSET ".$limit1."";
	    //echo "sql = ".$sql."<br>";
		$result = $BD->ejecutar_sql($sql);

?>
<html>
<head>
<title></title>
<link rel='stylesheet' href='./../funciones/translucido/css/lightbox.css' type='text/css' media='screen'/>
<script src='./../funciones/translucido/js/prototype.js' type='text/javascript'></script>
<script src='./../funciones/translucido/js/scriptaculous.js?load=effects' type='text/javascript'></script>
<script src='./../funciones/translucido/js/lightbox.js' type='text/javascript'></script> 
<!-- funcioones y estilos -->
<link href="./../estilo/estilo.css" rel="stylesheet" type="text/css">
<script src="./../funciones/funciones.js" language="javascript1.2"></script>
<script src="./../funciones/funciones_mail.js" language="javascript1.2"></script>
<script src="./../funciones/funciones_mail2.js" language="javascript1.2"></script>
<script src="./../funciones/funciones_perfil.js" language="javascript1.2"></script>
<script src="./../funciones/ajax.js"      language="javascript1.2"></script>
</head>
<body  topmargin="0" leftmargin="0">
<form action="<? $PHP_SELF;?>" method="post" id="usuario_mail_ver">

<?php
echo "<table width='650' height='0' align='center' border='0' cellpadding='0' cellspacing='0' >"; 
	   echo "	<tr>";
	      echo "<td class='cursor' valign='bottom' align='right' width='650'  height='20' background='../images/barralatestnewsxxx.png' >";
?>
		   <img src='./../images/DELETEMAIL.jpg' alt='DELETE' onClick="usuario_eliminar_mail('usuario_mail_ver', 'check_mailadmin');">&nbsp;&nbsp;&nbsp;</td>
<?php
		echo "	</tr>";
		echo "	<tr>";
	      echo "<td class='home2' align='center' width='650'  height='5' ></td>";
		echo "	</tr>";	
		echo "<tr>";
		 echo "<td id='tdmensajes1'></td>";
		echo "</td>";
		echo "<tr>";
		 echo "<td id='tdmensajes2'></td>";
		echo "</td>";		 
echo "</table>";		
/*if($nreg > $Registros)
  {
	echo "<table width='650'><tr><td  align='center'>";
	$a->barra_navega();
	echo "</td></tr></table>";
	}*/
	echo "<table id='menu'  width='650' height='0' align='center' border='0' cellpadding='0' cellspacing='4' bgcolor='#E3E6EF'>"; 
	   echo "	<tr>";
	      echo "<td class='home2' align='center' width='46'  height='10' >
		  <input type='checkbox' id='reset1' onclick=\"select_checkboxadmin('usuario_mail_ver', 'check_mailadmin', this);\"></td>";
		  echo "<td class='home2' align='center' width='222' height='10' >Subject</td>";
		  echo "<td class='home2' align='center' width='366' height='10' >Date</td>";
		   //echo "<td class='home5' align='center' width='530' >Mensaje</td>";
		echo "	</tr>";
		$i = 1;
		$id = 0;
	while($fila = $BD->fetch_array($result))
	{
		$id_mail	                  = $fila["id_mail"];
		$id_usuario                   = $fila["id_usuario"];
		$id_usuarioS                  = $fila["id_usuarioS"];
		$mensaje_mail	              = utf8_decode($fila["mensaje_mail"]);
		$fhingreso			          = $fila["fhingreso"];
		$newslastter                  = $fila["newslastter"];
		$revizado_mail                = $fila["revizado_mail"];
		$nom_usuario                  = $fila["nom_usuario"];
        $mensaje_mail = trim($mensaje_mail);
	    $quitar = array("%");
	    $mensaje_mail = str_replace($quitar, "'", $mensaje_mail);
		$fecha = fecha_mensaje($fhingreso);
        
		echo "<tr>";
		  if($revizado_mail == "NO")
		        {		  
				   echo "<td width='650' height='30' colspan='3' style='background-color:#8674A5;'>";
						echo "<table  width='650' cellpadding='0' cellspacing='0' border='0'>";
						   echo "<tr>";
								echo "<input type='hidden' id='id_mailadmin".$id."'  value='".$id_mail."'>";
								echo "<input type='hidden' id='id_usuarioadmin".$id."' value='".$id_usuario."'>";
							  echo "<td class='home2' align='center' width='46' height='0'  >
										<input type='checkbox' id='check_mailadmin".$id."'></td>"; 
							  echo "<td class='home2' align='center' width='252' height='0' >
							   <a href='#' onClick='usuario_mensaje_ver($i,$id_mail,$id_usuario,$id_usuarioS);' class='home2'>
								".$nom_usuario."
							   </a>	
							  </td>";
							  echo "<td class='home2' align='center' width='336' height='0'  >
							   <a href='#' onClick='usuario_mensaje_ver($i,$id_mail,$id_usuario,$id_usuarioS);' class='home2'>
								".$fecha."
							   </a>
							  </td>"; 
							 /* echo "<td class='cursor' align='center' width='46' height='0'>
							       <img src='./../images/xcircular.png' onClick='usuario_eliminar_mensaje_admin($id_mail,$id_usuario);' alt='DELETE'></td>";*/
							echo "</tr>"; 
						echo "</table>";
						echo "<tr>"; 
                                echo "<td class='td_oculto' colspan='3' id='tdmail2".$i."' align='center' width='20'></td>";
				           echo "<tr>";
					  echo "</td>";
				 }
			   else
				 { 
				   echo "<td width='650' height='30' colspan='3' style='background-color:#C7CDE7;'>";
						echo "<table  width='650' cellpadding='0' cellspacing='0' border='0'>";
						   echo "<tr>";
							  echo "<input type='hidden' id='id_mailadmin".$id."'  value='".$id_mail."'>";
								echo "<input type='hidden' id='id_usuarioadmin".$id."' value='".$id_usuario."'>";
							  echo "<td class='home2' align='center' width='46' height='0'  >
										<input type='checkbox' id='check_mailadmin".$id."'></td>";	
							  echo "<td class='home2' align='center' width='252' height='0'  >
							   <a href='#' onClick='usuario_mensaje_ver($i,$id_mail,$id_usuario,$id_usuarioS);' class='home2'>
								".$nom_usuario."
							   </a>	
							  </td>";
							  echo "<td class='home2' align='center' width='336' height='20'  >
							   <a href='#' onClick='usuario_mensaje_ver($i,$id_mail,$id_usuario,$id_usuarioS);' class='home2'>
								".$fecha."
							   </a>
							  </td>"; 
							  /*echo "<td class='cursor' align='center' width='46' height='0'>
							       <img src='./../images/xcircular.png' onClick='usuario_eliminar_mensaje_admin($id_mail,$id_usuario);' alt='DELETE'></td>";*/
							echo "</tr>";
							echo "<tr>"; 
                                echo "<td class='td_oculto' colspan='3' id='tdmail2".$i."' align='center' width='20'></td>";
				           echo "<tr>"; 
						echo "</table>";
					  echo "</td>";
				  }	     	  
		echo "</tr>";
	    $i++;
		$id++;
	}
   echo "</table>";
}
else
{
echo "<table width='650' height='0' align='center' border='0' cellpadding='0' cellspacing='0' >"; 
	   echo "	<tr>";
	      echo "<td class='home2' align='center' width='650'  height='20' background='../images/barralatestnewsxxx.png' ></td>";
		echo "	</tr>";
		echo "	<tr>";
	      echo "<td class='home2' align='center' width='650'  height='5' ></td>";
		echo "	</tr>";
echo "</table>";
echo "<table width='650' height='0' align='center' border='0' cellpadding='0' cellspacing='2' bgcolor='#E3E6EF'>"; 
	   echo "	<tr>";
	      /*echo "<td class='home2' align='center' width='22'  height='30' >
		  <input type='checkbox' id='reset1' onclick=\"select_checkbox('usuario_mail', 'check_mail', this);\"></td>";*/
		  echo "<td class='home2' align='center' width='198' height='30' >Subject</td>";
		  echo "<td class='home2' align='center' width='100' height='30' >Date</td>";
		   //echo "<td class='home5' align='center' width='530' >Mensaje</td>";
		echo "	</tr>";
		echo "	<tr>";
	      echo "<td class='home2' align='center' colspan='3' width='650'  height='30' >No Entries<td>";
		echo "</tr>";
echo "</table>";		
}
?>
</form>

</body>
</html>
  #2 (permalink)  
Antiguo 02/10/2009, 15:09
Avatar de towel  
Fecha de Ingreso: marzo-2009
Mensajes: 101
Antigüedad: 15 años, 1 mes
Puntos: 0
Respuesta: variable indefinida con checkbox

codigo javascritp
Código:
function usuario_eliminar_mail(nombreF, cadena)
{
	var quitar = "&;|;#";//los valores a remover del formulario
	var Formulario = document.getElementById(nombreF);//recibe el id del formulario
	var longitud = Formulario.elements.length;
	var campos = "";
	var separador;
	//alert (Formulario);
	separador = "";
	sw = 0;
	cont = 0;
	inicio = 1;
	numero_de_campos = 4;//sirve para poner el separador maestro, si quiero poner dos campos coloco 3 en numero de campos
	j = 0;
	if(document.getElementById("mens1") != null)
	{
		inicio = inicio + 1;
	}
	if(document.getElementById("mens2") != null)
	{
		inicio = inicio + 1;
	}
	for (i = inicio; i < longitud; i++)
	{
		if(cont >= 0)
		{
			if(sw == 0)
			{
				separador = "";
				sw = 1;
			}
			else
			{
				separador = "|";
			}
			cont = cont + 1;
			if(cont == numero_de_campos)
			{
				separador = "#";
				cont = 1;
			}
		}
		if(Formulario.elements[i].type == "checkbox")
		{
			if(Formulario.elements[i].checked == true)
				val = 1;
			if(Formulario.elements[i].checked == false)
				val = 0;
			valorF = val;
		}
		if(Formulario.elements[i].type != "checkbox")
		{
			valorF = Formulario.elements[i].value;
		}
		valorF = reemplazar_caracter(valorF, quitar);
		campos += separador+Formulario.elements[i].id+'='+(valorF);
	}//
	valores = "campos="+campos;
	alert(campos);
	ajax = nuevoAjax();
	ajax.open("POST", "./usuario_eliminar_mail.php", true);			
	ajax.onreadystatechange=function()
	{
		if(ajax.readyState == 1)
		{
			document.getElementById("tdmensajes1").innerHTML = "<img src='./../images/loading.gif' border='0'>";
			document.getElementById("tdmensajes2").innerHTML = "&nbsp;Actualizando datos...";
		}
		if(ajax.readyState == 4)
		{
			document.getElementById("tdmensajes1").innerHTML = "";
			document.getElementById("tdmensajes2").innerHTML = ajax.responseText;
			if(document.getElementById("mens") != null)
			  {
					var mens = document.getElementById("mens").value;
					//alert(mens);
					if(mens == 1)
					{
						alert("YOUR REQUEST WAS SUCCESSFULLY PROCESSED")
						location.href = "./../paginas/usuario_mail_ver.php";
						
					}
					if(mens == 2)
					{
						alert("ERROR try again")
					}
			    }
		 }
	 }
	ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
	ajax.send(valores);//*/
}
[/CODE]
codigo php elimina
Código:
<?php
include('../funciones/error.php');
include('../funciones/funciones.php');
include('../funciones/class_conexion.php');
include('../funciones/paginator.php');
include('../funciones/paginator_html.php');
$BD = new class_conexion();
valida_session();
global $mens, $id_mail_COM, $id_usuario_COM, $check_mail_COM,$campos,$registro ;
/*foreach ($_POST as $c => $v)
echo $c." = ".$v."<br>";*/

$campos = $_POST['campos'];

   	$fhregistro = getDateTime('tstamp');
	$campos = explode("#", $campos);
	$longitud = count($campos);
	//echo "Longitud ".$longitud."<br>";
	$mensaje = "RESULTADO DE LA OPERACION:\n\n";
	$cont = 0;//PARA CONTAR CUANTAS NO FUERON CHEQUEADAS

foreach($campos as $registro)
	{
		$fila = explode("|", $registro);
		$id_mail_i     = explode("=", $fila[0]);
	    $id_usuario_i  = explode("=", $fila[1]);
		$check_mail_i  = explode("=", $fila[2]);
		
		$id_mail      = $id_mail_i[1];
		$id_usuario   = $id_usuario_i[1];
		$check_mail   = trim($check_mail_i[1]);
		
		//echo "id_mail_COM = ".$id_mail_COM."<br> id_usuario_COM = ".$id_usuario_COM."<br> check_mail_COM =".$check_mail_COM."<br>";
		if( ($id_mail!= "") and ($id_usuario != "") and ($check_mail != "") )
		{
			//echo "IDSUCURSAL ".$idsucursalVEC." | CHK ".$check_sucursal." | DESC ".$descripcion."<br>";
			$prim = "SELECT id_usuario
					 FROM usuarios_mensajes_mail
					 WHERE id_mail = ".$id_mail." AND id_usuario = ".$id_usuario."";
			         $rprim = $BD->ejecutar_sql($prim);
					 $fila = $BD->fetch_array($rprim);
					 //echo "sql = ".$prim."<br>";
					 $id_usuario = $fila["id_usuario"];
						
			//echo  "mail = ".$check_mail_COM."<br> id = ".$id_usuario_COM."<br>  chekeo = ".$check_mail_COM."<BR>"; 
			if($check_mail == 1) 
			{
			    //echo "id_mail".$id_mail_COM; 
				/*if($check_mail_COM == 0)
				 {
				   $check_mail_COM == 1;
				 }*/ 
				$sql = "DELETE
						FROM usuarios_mensajes_mail
						WHERE id_mail = ".$id_mail." AND id_usuario = ".$id_usuario."";
				        $result = $BD->ejecutar_sql($sql);
						//echo "sql = ".$sql."<br>";
						if($result)
						{
						//echo "estoy aca";
							$mens = 1;
						}
						else
						{
						//echo "estoy aca2";
							$mens = 2;
						}//*/
			}
		  /*if( (trim($sql) == "") and ($cont == $longitud) )
			{
				$mens = 3;
				$mensaje.= "=> NO HA SELECCIONADO NINGUNA SUCURSAL.";
			}*/
		}//fin si hay sucursal*/
 }
/*else
{
	$mens = 4;
}*/
if($mens != "")
{
  echo "<input type='hidden' id='mens' value='".$mens."'>";
}  

?>
la variable viajan asi
campos = id_mailadmin0=2|id_usuarioadmin0=1|check_mailadmin 0=1#=undefined|id_mailadmin1=1|id_usuarioadmin1=1# check_mailadmin1=1|=undefined
que puede ser ayuda
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 11:35.