Forum Moderators: open
<?php
$con = mysql_connect("localhost","username","password");
if (!$con)
die('Could not connect: ' . mysql_error());
$db_found = mysql_select_db("chatdb", $con);
if ($db_found)
{
$query = "insert into chattable (username, message, msgread) values ('".$_POST['username']."','".$_POST['message']."','0')";
$result = mysql_query($query);
}
?>
<head>
<script type="text/javascript" src="javascript/prototype.js"></script>
<script language = "javascript">
var int=self.setInterval("insertTime()",2000);
function insertTime()
{
var ajaxx = new Ajax.Updater('datetime', 'loadHistory.php', {
method: 'get',
insertion: Insertion.Bottom
});
}
</script>
</head>
<body>
<form name="form1" id="form1" method="post">
<input name="sendmessage" type="submit" value="send">
</form>
<br />
<div id="datetime">
</div>
</body>
</html>
<?php
$con = mysql_connect("localhost","username","password");
if (!$con)
die('Could not connect: ' . mysql_error());
$db_found = mysql_select_db("chatdb", $con);
if ($db_found)
{
$query = "select username, message from chattable where msgread = '0'";
$result = mysql_query($query);
if (mysql_num_rows($result) > 0)
{
while ($rows = mysql_fetch_array($result))
{
echo "<table> \n";
echo "<tr> \n";
echo "<td>".$rows['username']."</td>";
echo "<td>".$rows['message']."</td>";
echo "<tr> \n";
echo "</table> \n";
}
}
$query = "update chathistory set msgread = 1 where msgread = '0'";
$result = mysql_query($query);
}
?>