-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
53 lines (48 loc) · 1.35 KB
/
index.php
File metadata and controls
53 lines (48 loc) · 1.35 KB
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
<?php
include 'db.php';
?>
<!DOCTYPE html>
<html>
<head>
<title> Simple PHP Chat App | Boahen Fred </title>
<link rel="stylesheet" type="text/css" href="style.css">
<script>
function ajax(){
var req = new XMLHttpRequest();
req.onreadystatechange = function(){
//if request is completed and successful
if(req.readyState == 4 && req.status==200){
//replace the data with the response gotten from the server
document.getElementById('chat').innerHTML=req.responseText;
}
}
req.open('GET', 'chat.php', true);
req.send();
}
</script>
</head>
<body onload="ajax();">
<div id="container">
<div id="chat_box">
<div id="chat"></div>
</div>
<form action="index.php" method="post">
<input type="text" name="name" placeholder="Enter Name .." />
<textarea name="message" placeholder="Enter Message .." ></textarea>
<input type="submit" name="submit" value="Send"/>
</form>
<?php
if(isset($_POST['submit'])){
$name=$_POST['name'];
$message=$_POST['message'];
$date=date("F j, Y, g:i a");
$query="INSERT INTO chat (name,message,date) values('$name','$message','$date')";
$run = $con -> query($query);
if($run){
echo "<embed loop='false' src='youGotmail.wav' autoplay='true' hidden='true' />";
}
}
?>
</div>
</body>
</html>