-
Notifications
You must be signed in to change notification settings - Fork 0
/
message.php
112 lines (109 loc) · 4.39 KB
/
message.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
103
104
105
106
107
108
109
110
111
112
<?php
/**
* Created by PhpStorm.
* User: ryanh
* Date: 7/28/2018
* Time: 6:57 PM
*/
session_start();
include 'connection.php';
if(!isset($_SESSION['username'])){
header("Location:login.php");
}
?>
<?php
$sqlsetread= "update messages set msgread = 'yes' where receiver = '".$_SESSION["username"]."'
and sender = '".$_POST["contact"]."' and msgread = 'no';";
$resultread= mysqli_query($conn, $sqlsetread);
?>
<html id="html">
<head>
<title>Game Swap</title>
<link rel="stylesheet" href="css/bootstrap.css">
<link rel="stylesheet" href="css/post.css">
<link rel="stylesheet" href="css/all.min.css">
</head>
<body id="body">
<nav class="navbar navbar-expand-lg navbar-dark fixed-top" style="background-color: black">
<div class="container">
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarToggler" aria-controls="navbarToggler" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<a class="navbar-brand" href="home.php"><i class="fas fa-gamepad"></i> Game Swap</a>
<div class="collapse navbar-collapse" id="navbarToggler">
<ul class="navbar-nav mr-auto mt-2 mt-lg-0">
<li class="nav-item">
<a class="nav-link" href="home.php">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" href="myposts.php">My Posts</a>
</li>
<li class="nav-item">
<a class="nav-link" href="newpost.php">New Post</a>
</li>
<li class="nav-item">
<a class="nav-link" href="users.php">Users</a>
</li>
<li class="nav-item">
<a class="nav-link" href="games.php">All Games</a>
</li>
<li class="nav-item">
<?php
echo "<a class=\"nav-link\" href=\"messages.php\">Inbox(";
$sqlunread = "SELECT * FROM messages where receiver =\"".$_SESSION["username"]."\" and msgread = 'no' order by time desc";
$unread = mysqli_query($conn, $sqlunread);
echo mysqli_num_rows($unread);
echo ")</a>";
?>
</li>
</ul>
<ul class="navbar-nav ml-auto my-2 my-lg-0">
<li class="nav-item">
<a class="nav-link" href="myinfo.php"><?php
echo "<i class=\"fas fa-user\"></i> " .$_SESSION['username'].""
?></a>
</li>
<li class="nav-item">
<a class="nav-link" href="login.php">Log Out <i class="fas fa-sign-out-alt"></i></a>
</li>
</ul>
</div>
</div>
</nav>
<div class="container" id="posts">
<?php
$sql = "SELECT * FROM messages where (sender =\"".$_SESSION["username"]."\" and receiver =\"".$_POST["contact"]."\")
or (sender =\"".$_POST["contact"]."\" and receiver =\"".$_SESSION["username"]."\") order by time";
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) > 0) {
// output data of each row
echo "<div id='post'><h2>Conversation with ".$_POST["contact"]."</h2>";
while($row = mysqli_fetch_assoc($result)) {
echo "<hr><h4>" . $row["sender"]. "</h4><br>
<h6>" . $row["msg"]. "</h6>";
}
echo "</div>";
} else {
echo "0 results";
}
mysqli_close($conn);
?>
<div id="post">
<form method='post' action='sendmessage.php'>
<div class="form-group">
<label for="message">Type Message</label>
<input name='message' type="text" class="form-control" id="message" placeholder="Your Message">
</div>
<div class="form-group">
<?php echo "<input name='contact' type='hidden' class='form-control' id='contact' value='".$_POST["contact"]."'>"
?>
</div>
<button type="submit" class="btn btn-success">Send</button>
</form>
</div>
<div style='margin-bottom: 400px'>
</div>
</div>
<script type="text/javascript" src="js/home.js"></script>
</body>
</html>