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í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 originalvar xmlhttp;
function showUser(str,estado)
{
xmlhttp=GetXmlHttpObject();
if (xmlhttp==null)
{
alert ("Browser does not support HTTP Request");
return;
}
var url="getuser2.php";
url=url+"?q="+str+"&estado="+estado;
url=url+"&sid="+Math.random();
xmlhttp.onreadystatechange=stateChanged;
xmlhttp.open("GET",url,true);
xmlhttp.send(null);
}
function stateChanged()
{
if (xmlhttp.readyState==4)
{
document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
}
}
function GetXmlHttpObject()
{
if (window.XMLHttpRequest)
{
// code for IE7+, Firefox, Chrome, Opera, Safari
return new XMLHttpRequest();
}
if (window.ActiveXObject)
{
// code for IE6, IE5
return new ActiveXObject("Microsoft.XMLHTTP");
}
return null;
}
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.