Ver Mensaje Individual
  #2 (permalink)  
Antiguo 16/05/2009, 17:01
Martin2006
 
Fecha de Ingreso: mayo-2006
Mensajes: 45
Antigüedad: 18 años
Puntos: 0
Respuesta: valor de Checkbox y Ajax

ACA PROBE DE UNA FORMA MAS SENCILLA: Resultado el mismo, me actualiza el nombre y apellido pero el checkbox que tengo como set 'Y','N' en la BD SIEMPRE SE GRABA COMO Y. no entiendo que pasa, ya me estoy volviendo loco.

una ayudita porfa, gracias


$_POST['id_usuario']=1;
$_POST['id']=1;
if(isset($_POST['Submit']) && !empty($_POST['Submit'])) {
$updateSQL = sprintf("UPDATE perfiles SET id_usuario=%s, nombre=%s, apellido=%s, busco=%s WHERE id=%s",
GetSQLValueString($_POST['id_usuario'], "int"),
GetSQLValueString($_POST['nombre'], "text"),
GetSQLValueString($_POST['apellido'], "text"),
GetSQLValueString(isset($_POST['busco']) ? "true" : "", "defined","'Y'","'N'"),
GetSQLValueString($_POST['id'], "int"));

mysql_select_db($database_perfil, $perfil);
$Result1 = mysql_query($updateSQL, $perfil) or die(mysql_error());
}

$colname_Recordset1 = "-1";
if (isset($_SESSION['id_usuario'])) {
$colname_Recordset1 = $_SESSION['id_usuario'];
}
mysql_select_db($database_perfil, $perfil);
$query_Recordset1 = sprintf("SELECT * FROM perfiles WHERE id_usuario = %s", GetSQLValueString($colname_Recordset1, "int"));
$Recordset1 = mysql_query($query_Recordset1, $perfil) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);

//en este ejemplo lo enviamos a la misma página


?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>test</title>
<script>
//acá cada uno crea el objeto a su manera
function aj(){
if(window.XMLHttpRequest){
return new XMLHttpRequest();
}
else{
try{
return new ActiveXObject('Microsoft.XMLHTTP');
}catch(e){
alert('tu navegador no soporta ajax');
return false;
}
}
}
function sendAndLoad(){
var rpc=aj();
if(rpc){
//si pudo crearse el objeto, avanzamos (respetar el orden)
rpc.open('POST','<?php echo basename($_SERVER['PHP_SELF']) ?>',true);
rpc.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
//preparamos las variables a enviar
var aEnviar='';

for(ii=0; ii<arguments.length;ii++){
//usamos el objeto arguments para obtener y parsear los datos a enviar
//encodeURI es semejante a urlencode de PHP
aEnviar+=arguments[ii].desc+'='+encodeURI(arguments[ii].dato)+'&';
}
//creamos una función anónima que sirva de handler
rpc.onreadystatechange=function(){
if(rpc.readyState==4){
//nos conectamos, recibimos y hacemos algo con lo que recibimos si queremos
//en este caso, mostramos lo que enviamos
document.getElementById('pp').style.display='block ';
document.getElementById('pp').style.color='green';
document.getElementById('pp').innerHTML=rpc.respon seText;
}else{
//no nos conectamos todavía y mostramos la precarga
document.getElementById('pp').style.display='block ';
}
}
//Recién ahora, que tenemos todo lo anterior terminado, podemos enviar el request
rpc.send(aEnviar);
}
}
//asignamos la función al botón de envío al cargar la página, así no tocamos el html
window.onload=function(){
document.getElementById('Submit').onclick=function (){
//pasamos objetos escritos en notación json como argumentos
sendAndLoad(
{desc:'nombre',dato:document.getElementById('nombr e').value},
{desc:'apellido',dato:document.getElementById('ape llido').value},
{desc:'busco',dato:(document.getElementById('busco ').checked)?document.getElementById('busco').value :'N'},
{desc:'Submit',dato:document.getElementById('Submi t').value});
}
}
</script>
</head>

<body>
<form action="" method="post" name="form1" id="form1">
<table align="center">
<tr valign="baseline">
<td nowrap="nowrap" align="right">Id_usuario:</td>
<td><input type="hidden" name="id_usuario" id="id_usuario" value="<?php echo htmlentities($row_Recordset1['id_usuario'], ENT_COMPAT, 'iso-8859-1'); ?>" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">Nombre:</td>
<td><input type="text" name="nombre" id="nombre" value="<?php echo htmlentities($row_Recordset1['nombre'], ENT_COMPAT, 'iso-8859-1'); ?>" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">Apellido:</td>
<td><input type="text" name="apellido" id="apellido" value="<?php echo htmlentities($row_Recordset1['apellido'], ENT_COMPAT, 'iso-8859-1'); ?>" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">Busco:</td>
<td><input type="checkbox" name="busco" id="busco" value="" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">&nbsp;</td>
<td><input type="button" id="Submit" name="Submit" value="Actualizar registro" /></td>
</tr>
</table>

</form>
<p>&nbsp;</p>


<div id="pp" style="display:none;color:#F00">Cargando...</div>
</body>
</html>