![Antiguo](http://static.forosdelweb.com/fdwtheme/images/statusicon/post_old.gif)
16/05/2012, 14:09
|
| | Fecha de Ingreso: diciembre-2011 Ubicación: coruña
Mensajes: 36
Antigüedad: 13 años, 1 mes Puntos: 1 | |
Respuesta: como solucionar?? ahora lo tengo asi y sigue sin coger la id donde fallo?? Código PHP: <?php
session_start();
if
(isset($_SESSION['k_username'])) {
}else{
?>
<SCRIPT LANGUAGE="javascript">
location.href = "index.php";
</SCRIPT>
<?php
}
include("connect.php");
//
if($_GET["Enviar"]=="si")
{
$max="select max(id) from chat";
$max=mysql_query($max);
$max=mysql_result($max,0,0)+1;
$fecha=date("Y/m/d - H:i:s");
//
$insert="insert into chat values(".$max.",'".htmlentities(utf8_decode($_REQUEST["comentario"]))."','".$fecha."','".($_SESSION["k_username"])."','".$_GET["id"]."')";
if(trim($_REQUEST["comentario"])!=NULL)
{
$insert=mysql_query($insert);
}
exit();
}
elseif($_GET["Leer"]=="si")
{
header("Cache-Control: no-store, no-cache, must-revalidate");
$select="select * from chat WHERE para='".$idd."' order by id desc ";
$select=mysql_query($select);
while($row = mysql_fetch_array($select))
{
if($row["comentario"]!=NULL)
{
echo "<strong> en viado por ".$row["user"]." a las ".$row["fecha"]."</strong> - ".$row["comentario"]."<hr>";
}
}
exit();
}
elseif($_GET["Hash"]=="si")
{
header("Cache-Control: no-store, no-cache, must-revalidate");
$max="select max(id) from chat";
$max=mysql_query($max);
$max=mysql_result($max,0,0);
//
$select="select * from chat where id=".$max." limit 1";
$select=mysql_query($select);
//
$id=mysql_result($select,0,"id");
$comentario=mysql_result($select,0,"comentario");
$fecha=mysql_result($select,0,"fecha");
//
$hash=$id.$comentario.$fecha;
if($hash==NULL)
{
echo "vacio";
}
else
{
$hash=md5($id.$comentario.$fecha);
echo $hash;
}
exit();
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="es">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>MiniChat :)</title>
<script>
var ID_CHAT= <?php echo $_GET['id']; ?>;
</script>
<script type="text/javascript" src="ajax.js"></script>
<script type="text/javascript">
setInterval("fajax3()",5000);
</script>
</head>
<body>
<textarea cols="50" id="comentario" > </textarea>
<input type="button" value="enviar" onClick="fajax()" />
<div id="chat">
</div>
<input type="hidden" id="id_hash" value="" />
<script type="text/javascript">
document.getElementById('comentario').value="";
document.getElementById('comentario').focus();
fajax3();
</script>
</body>
</html> y el ajax
Código:
function ajaxFunction()
{
var xmlHttp;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
return xmlHttp;
}
catch (e)
{
// Internet Explorer
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
return xmlHttp;
}
catch (e)
{
try
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
return xmlHttp;
}
catch (e)
{
alert("Your browser does not support AJAX!");
return false;
}
}
}
}
function fajax()
{
var comentario;
comentario = document.getElementById('comentario').value;
var ajax;
ajax = new ajaxFunction();
ajax.open("POST","?Enviar=si&id=ID_CHAT",true);
ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
ajax.send("comentario="+comentario);
document.getElementById('comentario').value="";
document.getElementById('comentario').focus();
fajax3();
}
function fajax2()
{
var ajax;
ajax=new ajaxFunction();
ajax.onreadystatechange=function()
{
if(ajax.readyState==4)
{
document.getElementById('chat').innerHTML=ajax.responseText;
}
}
ajax.open("GET","?Leer=si",true);
ajax.send(null);
}
function fajax3()
{
var ajax;
ajax=new ajaxFunction();
var hashviejo;
hashviejo=document.getElementById('id_hash').value;
ajax.onreadystatechange=function()
{
if(ajax.readyState==4)
{
if(hashviejo!=ajax.responseText && ajax.responseText!='vacio')
{
document.getElementById('id_hash').value=ajax.responseText;
fajax2();
}
}
}
ajax.open("GET","?Hash=si",true);
ajax.send(null);
}
|