-
Notifications
You must be signed in to change notification settings - Fork 0
/
search.php
171 lines (151 loc) · 6.56 KB
/
search.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
<?php
// Start the session
session_start();
?>
<html>
<head>
<title>CoolPics Search</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="//fonts.googleapis.com/css?family=Open+Sans:300,400,600,700&lang=en" />
<link rel="stylesheet" type="text/css" href="style.css" />
<style>
.scrollable {
height: 80px; /* or any value */
overflow-y: auto;
}
</style>
</head>
<body>
<nav class="navbar navbar-inverse">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#topNavBar">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="index.html">CoolPics</a>
</div>
<!-- items -->
<div class="collapse navbar-collapse" id="topNavBar">
<ul class="nav navbar-nav">
<li class="active">
<a href="pics.php">
<span class="glyphicon glyphicon-th-large" aria-hidden="true"></span>
Pics
</a>
</li>
</ul>
<form class="navbar-form navbar-left" role="search" method="get" action="search.php">
<div class="form-group">
<input type="text" class="form-control" name="q" placeholder="Images by Username">
</div>
<button type="submit" class="btn btn-default">Search</button>
</form>
<ul class="nav navbar-nav navbar-right">
<li class="">
<a href="https://github.com/arindam-modak" style="text-decoration:none;"><i class="fa fa-github" aria-hidden="true"></i> ADM</a>
</li>
<li class="">
<a href="addpic.php">
<span class="glyphicon glyphicon-plus" aria-hidden="true"></span>
Add Pic
</a>
</li>
<li class="">
<a href="FileUpload.php">
<span class="glyphicon glyphicon-plus" aria-hidden="true"></span>
Upload Pic
</a>
</li>
<li class="">
<a href="register.php">
<span class="glyphicon glyphicon-th-large" aria-hidden="true"></span>
Register
</a>
</li>
<li class="">
<a href="login.php">
<span class="glyphicon glyphicon-user" aria-hidden="true"></span>
login
</a>
</li>
<li class="">
<a href="logout.php">
<span class="glyphicon glyphicon-off" aria-hidden="true"></span>
Logout
</a>
</li>
</ul>
</div>
</div>
</nav>
<?php
if (isset($_SESSION['username']))
{
}
else { $_SESSION['username']=""; }
if($_SESSION['username']!=""){
echo '<pre style="opacity: 0.7;margin-left:20px;margin-right:20px;"> <i><h1> <font color="teal">Hello! </font></i><b>'.$_SESSION['username'].'</b></h1></pre><hr>';
}
else { header("Location: https://iit2016036.000webhostapp.com/login.php"); /* Redirect browser */
exit(); }
$searchName = $_REQUEST['q'];
$con = mysqli_connect("localhost", "root", "");
echo "<center><b><h2><u>".$searchName." </u></h2></b></center><br><hr>";
mysqli_select_db($con, "");
$sql = "Select * from tblpics";
$rs = mysqli_query($con, $sql);
$flag1 = 0;
echo '<div class="container"><div class="row">';
while($row = mysqli_fetch_array($rs))
{
if($row['colName']==$searchName){
if($row['colHitLike']==1)
{
$sql1 = "UPDATE tblpics SET colLike = colLike + 1 WHERE colId =" . $row['colId'] . "";
$rt = mysqli_query($con, $sql1);
}
$sql1 = "UPDATE tblpics SET colHitLike = 1 WHERE colId =" . $row['colId'] . "";
$rt = mysqli_query($con, $sql1);
$flag1=1;
echo '<div class="col-lg-4 col-md-4 col-sm-12 col-xs-12"><center>';
echo '<div class="thumbnail" style="margin-left:20px;margin-right:20px;">';
echo '<img src="'.$row['colUrl'].'" style="height:200px;width:280px;">';
echo '<b><a href="#" style="text-decoration: none">'.$row['colName'].'</a></b><br>';
echo '<div class="row"><div class="col-md-4"></div> <div class="col-md-2"><div class="thumbnail" style="height:32px;width:40px;"><form action="likes.php"><input type="hidden" name="txtLike" value="'.$row['colId'].'">
<button type="submit"><span class="glyphicon glyphicon-star" aria-hidden="true"></span></button></form>'.$row['colLike'].'</div></div>
<div class="col-md-2"><div class="thumbnail" style="height:32px;width:40px;"><form action="delete.php"><input type="hidden" name="txtDelete" value="'.$row['colId'].'">
<button type="submit"><span class="glyphicon glyphicon-trash" aria-hidden="true"></span></button></form></div></div>
</div><h3><br><hr><u><b><i>Comments: </u></b></i></h3>
</center>';
$sql1 = "Select * from tblcomment Where colId =" . $row['colId'] . "";
$rs1 = mysqli_query($con, $sql1);
echo '<div class="scrollable"><ul type="square">';
$flag2=0;
while($row1 = mysqli_fetch_array($rs1))
{
echo '<li><b>'.$row1['colCommentName'].'</b> : '.$row1['colComment'].'</li>';
$flag2 = 1;
}
echo '</ul></div><hr>';
echo '<form action="comment.php" style="margin-left:20px"><input type="hidden" name="txtComId" value="'.$row['colId'].'">
Comment : <input type="text" name="txtComment" style="width:200px"><button type="submit" value="comment">ADD</button></form></div>';
if(($flag1)%3==0)
{ echo '</div></div><div class="container"><div class="row">'; }
$sql1 = "UPDATE tblpics SET colHitLike = 0 WHERE colId =" . $row['colId'] . "";
$rt = mysqli_query($con, $sql1);
}
}
echo '</div></div>';
if($flag1==0)
{
echo "<center><h2>".$searchName." has no Pics yet!!!</h2></center>";
}
mysqli_close($con);
?>
</body>
</html>