Ver Mensaje Individual
  #3 (permalink)  
Antiguo 14/03/2010, 15:30
ahome8990
 
Fecha de Ingreso: enero-2010
Mensajes: 39
Antigüedad: 14 años, 3 meses
Puntos: 0
Respuesta: pubicar y despublicar??

Disculpen que retome el tema, si sabia que era con sql basico pero , el asunto es que lo debia hacer en tiempo real; el detalle aqui es que estoy usando estos scripts:

este se llama ajaxphp.html:

Código HTML:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Documento sin t&iacute;tulo</title>
<script type="text/javascript" src="selectuser2.js"></script>
</head>

<body>
<form>
<?php

$con = mysql_connect('localhost', 'usuario', 'contraseña');
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("datospersona", $con);

$sql="SELECT * FROM user";

$result = mysql_query($sql);

echo "<table border='1'>
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Age</th>
<th>Hometown</th>
<th>Job</th>
<th>Estado</th>
</tr>";

while($row = mysql_fetch_array($result))
  {
  
  echo "<tr>";
  echo "<td>" . $row['FirstName'] . "</td>";
  echo "<td>" . $row['LastName'] . "</td>";
  echo "<td>" . $row['Age'] . "</td>";
  echo "<td>" . $row['Hometown'] . "</td>";
  echo "<td>" . $row['Job'] . "</td>";
  echo "<td>";
  if($row['estado']==1)
  {
  ?>
  <input id='estado' name='estado' type='checkbox' checked='checked'  value='1'        							onclick="showUser(<?php echo $row['id'];?>,this.value)"/>
  <?php 
  }
  else
  {
  ?>
  <input id='estado' name='estado' type='checkbox' value='0' onclick='showUser(<?php echo $row['id']; ?>,this.value)'/>
 <?php
  }
  echo "</td>";
  echo "</tr>";
  }
echo "</table>";
?>
</select>
</form>
<br />
<div id="txtHint"><b>Person info will be listed here.</b></div>
</body>
</html> 
este es el ajax selectuser2.php:

Código Javascript:
Ver original
  1. var xmlhttp;
  2.  
  3. function showUser(str,estado)
  4. {
  5. xmlhttp=GetXmlHttpObject();
  6. if (xmlhttp==null)
  7.   {
  8.   alert ("Browser does not support HTTP Request");
  9.   return;
  10.   }
  11. var url="getuser2.php";
  12. url=url+"?q="+str+"&estado="+estado;
  13. url=url+"&sid="+Math.random();
  14. xmlhttp.onreadystatechange=stateChanged;
  15. xmlhttp.open("GET",url,true);
  16. xmlhttp.send(null);
  17. }
  18.  
  19. function stateChanged()
  20. {
  21. if (xmlhttp.readyState==4)
  22. {
  23. document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
  24. }
  25. }
  26.  
  27. function GetXmlHttpObject()
  28. {
  29. if (window.XMLHttpRequest)
  30.   {
  31.   // code for IE7+, Firefox, Chrome, Opera, Safari
  32.   return new XMLHttpRequest();
  33.   }
  34. if (window.ActiveXObject)
  35.   {
  36.   // code for IE6, IE5
  37.   return new ActiveXObject("Microsoft.XMLHTTP");
  38.   }
  39. return null;
  40. }

y este es getuser2.php:
Código PHP:
<?php
$id
=$_GET["q"];
$estado=$_GET["estado"];
$con mysql_connect('localhost''usuario''contraseña');
if (!
$con)
  {
  die(
'Could not connect: ' mysql_error());
  }

mysql_select_db("datospersona"$con);
echo 
$id;
echo 
$estado;
$sql="UPDATE user SET estado='$estado' where id='$id'";

$result mysql_query($sql);


mysql_close($con);
?>
si me muestra los valores cuando marco los checkbox, pero no me actualiza los valores. estoy mandando el valor pero no realiza ninguna accion.