-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathhome.php
56 lines (45 loc) · 1.19 KB
/
home.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php include 'db.php'; ?>
<?php include('server.php'); ?>
<!DOCTYPE html>
<html>
<head>
<title>Chat Box</title>
<link rel="stylesheet" href="style.css" media="all">
<script type="text/javascript">
function ajax() {
var req = new XMLHttpRequest();
req.onreadystatechange = function() {
if(req.readyState == 4 && req.status == 200) {
document.getElementById('chat').innerHTML = req.responseText;
}
}
req.open('GET', 'chat.php', true);
req.send();
}
setInterval(function() {ajax()}, 1000);
</script>
</head>
<body onload="ajax();">
<div id="container">
<div id="chat_box">
<div id="chat"></div>
</div>
<form method="post" action="home.php">
<textarea name="msg" placeholder="enter message" maxlength="150"></textarea>
<input type="submit" name="submit" value="Send it">
<p><a href="home.php?logout='1'" style="color: red;">Logout</a></p>
</form>
<?php
if(isset($_POST['submit'])) {
$msg = $_POST['msg'];
$name=$_SESSION['username'];
$query = "INSERT INTO chat (name,msg) VALUES ('$name','$msg') ";
$run = $con->query($query);
if($run) {
echo "<embed loop='false' src='chat.wav' hidden='true' autoplay='true'/>";
}
}
?>
</div>
</body>
</html>