-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.php
102 lines (76 loc) · 2.1 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<?php require("layout.php"); ?>
<?php render("header", ["title"=>"Home"]); ?>
<?php
// if the user hadn't login
if(empty($_SESSION['id']))
{
echo "<script>location.href='login.php';</script>";
}
/**
* Display the chatbox
*/
require("dbconfig.php");
// Create connection
$conn = new mysqli($host, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
if(isset($_POST['reg']))
{
$sessionname=$_SESSION['name'];
$message=$_POST['message'];
$sql1="INSERT INTO messages (username,message) VALUES('".$sessionname."','".$message."')";
if($conn->query($sql1)==true)
{
echo "message sent";
echo "<br>";
}
}
?>
<script type="text/javascript" src="js/jquery-1.10.2.min.js" ></script>
<!-- Dispaly the message, just next line only -->
<p name="chatroom" class="chat" id="display"></p>
<form onsubmit="return loaddata();" method="post">
<fieldset>
<br>
<div class="form-group">
<input type="text" name="message" onkeyup="loaddata();" onfocus="loaddata();" placeholder="Enter Your Message" class="form-group"/>
</div>
<div class="form-group">
<button class="btn btn-default" name="reg" type="submit">Send</button>
</div>
</fieldset>
</form>
<script type="text/javascript">
$(document).ready(function(){
$('#display').animate({
scrollTop: $('#display').get(0).scrollHeight}, 2000);
});
window.addEventListener("online",function(){loaddata();});
window.addEventListener("focus",function(){loaddata();});
window.addEventListener("mouseover",function(){loaddata();});
function loaddata()
{
$.ajax({
type: 'post',
url: 'select.php',
data: {
},
success: function (response) {
$( '#display' ).html(response);
}
});
}
setInterval(function(){
$.ajax({
url:'select.php',
data:{ajaxget:true},
method:'post',
success:function(data){
$('#result').html(response);
}
})
},200);
</script>
<?php render("footer"); ?>