-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.php
52 lines (46 loc) · 1.02 KB
/
index.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
<?php
include 'db.php';
?>
<!DOCTYPE html>
<html>
<head>
<title>chat system</title>
<link rel="stylesheet" href="style.css" media="all"/>
<script>
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="index.php">
<input type="text" name="name" placeholder="enter name" />
<textarea name="msg" placeholder="enter message"></textarea>
<input type="submit" name="submit" value="send it"/>
</form>
</div>
<?php
if(isset($_POST['submit'])){
$name=$_POST['name'];
$msg=$_POST['msg'];
$query="INSERT INTO chat(name,msg) values('$name','$msg')";
$run=$con->query($query);
if($run){
echo "<embed loop='false' src='2.mp3' hidden='true' autoplay='true' />";
}
}
?>
</body>
</html>