Skip to content

Commit

Permalink
Search function implementation
Browse files Browse the repository at this point in the history
-implemented through LIKE sql query
-updated search,message submit buttons
--To Do List:
-Perform check before null queries(search,message submit....)
 so that it won't go through
-style 'go back' in search.php
  • Loading branch information
hiimdoublej committed May 29, 2016
1 parent 9066a6c commit c47e423
Show file tree
Hide file tree
Showing 5 changed files with 180 additions and 16 deletions.
21 changes: 15 additions & 6 deletions home.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,17 @@
</div>
</div>
</div>
<div class="table-title">
<h3>Bulletin Board</h3>
</div>

<form action="search.php" method="POST">
<input type="hidden" name="search_submit" value="1" />
<textarea name="message_target" id = 'msg_search_box'></textarea>
<button type="submit" id ='msg_search'>Search for message</button>
<br />
</form>


<?php
$sql_select = "SELECT msg_id,msg, username,msg_time,uid
Expand All @@ -65,14 +76,11 @@
if(count($result) > 0)
{
?>
<div class="table-title">
<h3>Bulletin Board</h3>
</div>
<table class = "table-fill">
<tr><th>Message</th>
<th>By</th>
<th>Time</th>
<th id="actions">Actions</th>
<th id="actions">Delete</th>
<?php
while($row=$result->fetch(PDO::FETCH_OBJ))
{
Expand All @@ -85,7 +93,8 @@
<td id="actions">
<form action="home.php" method="POST" >
<button type="submit" id="del_btn" name="delete_action" value ="delete"
style="border:0;background transparent;"/>
style="border:0;background transparent;"
onclick="return confirm('Delete this message?')"/>
<img style ="width:30px;height:30px;"src="icons/delete.png" class = "invert" title = "Delete This Message" alt="submit" />
<?php
echo "<input type='hidden' name='del_msg_id' value=".$row->msg_id.">"
Expand All @@ -112,7 +121,7 @@
<form action="home.php" method="POST">
<input type="hidden" name="submit" value="1" />
<textarea name="message" id = 'msg'></textarea><br />
<input type="submit" id ='msg_submit' value="Submit message!" />
<button type="submit" id ='msg_submit'>Submit message</button>
</form>

<?php
Expand Down
4 changes: 1 addition & 3 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,15 @@
}
if(isset($_POST['btn-login']))
{
var_dump($_POST);
$email = $conn->quote($_POST['email']);
$upass = md5($_POST['pass']);
$sql = "SELECT * FROM users WHERE email=$email";
$res=$conn->query($sql);
$row=$res->fetch(PDO::FETCH_BOTH);
var_dump($row);
var_dump($upass);
if($row['password']==$upass)
{
$_SESSION['user'] = $row['user_id'];
$_SESSION['username'] = $row['username'];
?>
<script>alert('Login successful');</script>
<?php
Expand Down
2 changes: 1 addition & 1 deletion register.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
<td><input type="password" name="pass" placeholder="Your Password" required /></td>
</tr>
<tr>
<td><button type="submit" name="btn-signup">Sign Me Up</button></td>
<td><button type="submit" name="btn-signup" id ="signup">Sign Me Up</button></td>
</tr>
<tr>
<td><a href="index.php">Sign In Here</a></td>
Expand Down
95 changes: 95 additions & 0 deletions search.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
<?php
session_start();
include_once 'dbconnect.php';
if(!isset($_SESSION['user']))
{
header("Location: index.php");
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Welcome - <?php echo $userRow['email']; ?></title>
<link rel="stylesheet" href="style.css" type="text/css" />
</head>
<body>
<div id="header">
<div id="left">
<label>410221009 DBMS final project</label>
</div>
<div id="right">
<div id="content">
hi' <?php echo $_SESSION['username'];?>&nbsp;<a href="logout.php?logout">Sign Out</a>
</div>
</div>
</div>
<div class="table-title">
<?php
echo "<h3>Search Results of '".$_POST['message_target']."'</h3>";
?>
</div>

<?php
if(isset($_POST['search_submit']))
{
$sequence = $_POST['message_target'];
try
{
$sql_search = "SELECT msg_id,msg, username,msg_time,uid
FROM messages, users
WHERE messages.uid = users.user_id AND msg LIKE '%$sequence%'
ORDER BY `messages`.`msg_time` DESC";
$result = $conn->query($sql_search);
if(count($result) > 0)
{
?>
<table class = "table-fill">
<tr><th>Message</th>
<th>By</th>
<th>Time</th>
<th id="actions">Delete</th>
<?php
while($row=$result->fetch(PDO::FETCH_OBJ))
{
echo "<tr><td>".$row -> msg."</td>";
echo "<td>".$row -> username."</td>";
echo "<td>".$row -> msg_time."</td>";
if($_SESSION['user']==$row->uid)
{
?>
<td id="actions">
<form action="home.php" method="POST" >
<button type="submit" id="del_btn" name="delete_action" value ="delete"
style="border:0;background transparent;"
onclick="return confirm('Delete this message?')"/>
<img style ="width:30px;height:30px;"src="icons/delete.png" class = "invert" title = "Delete This Message" alt="submit" />
<?php
echo "<input type='hidden' name='del_msg_id' value=".$row->msg_id.">"
?>
</form>
</a>
</td>
</tr>
<?php
}
else
{
echo "<td></td></tr>";
}
}
echo "</table>";
}
else
{
echo "No message here ! be the first !";
}

}
catch(Exception $e)
{
die(var_dump($e));
}
}
?>
<a href="home.php" id="back_to_home">Go Back</a>
74 changes: 68 additions & 6 deletions style.css
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@
}
table#login
{
border:solid #dcdcdc 5px;
padding:25px;
box-shadow: 0px 0px 1px rgba(0,0,0,0.2);
}
table tr,td
{
Expand All @@ -25,8 +23,8 @@ table tr td input
{
width:97%;
height:45px;
border:solid #e1e1e1 1px;
border-radius:3px;
border:solid #3e94ec 1px;
border-radius:0px;
padding-left:10px;
font-family:Verdana, Geneva, sans-serif;
font-size:16px;
Expand All @@ -50,6 +48,23 @@ table tr td button#login
font-weight:bolder;
text-transform:uppercase;
}

button#signup
{
width:100%;
height:45px;
border:0px;
background:#3e94ec;
background:-moz-linear-gradient(top, #595959 , #515151);
border-radius:3px;
box-shadow: 1px 1px 1px rgba(1,0,0,0.2);
color:#f9f9f9;
font-family:Verdana, Geneva, sans-serif;
font-size:18px;
font-weight:bolder;
text-transform:uppercase;
}

table tr td button:active
{
position:relative;
Expand Down Expand Up @@ -119,8 +134,44 @@ textarea#msg{
background-repeat: no-repeat;
resize : none;
}
input#msg_submit{
margin-left:40px;
textarea#msg_search_box{
margin-left:40px;
width: 40%;
height: 20px;
border: 3px solid #cccccc;
padding: 5px;
font-family: Tahoma, sans-serif;
background-position: bottom right;
background-repeat: no-repeat;
resize : none;
}
button#msg_submit{
border: 2px solid #fafafa;
width: 20%;
margin-left:40px;
height:45px;
background:#3e94ec;
background:-moz-linear-gradient(top, #595959 , #515151);
border-radius:3px;
color:#f9f9f9;
font-family:Verdana, Geneva, sans-serif;
font-size:18px;
font-weight:bolder;
text-transform:uppercase;
}
button#msg_search{
border: 2px solid #fafafa;
position: relative;
top:-12px;
width:20%;
height:35px;
background:#3e94ec;
background:-moz-linear-gradient(top, #595959 , #515151);
color:#f9f9f9;
font-family:Verdana, Geneva, sans-serif;
font-size:18px;
font-weight:bolder;
text-transform:uppercase;
}

/* css for home page */
Expand Down Expand Up @@ -291,4 +342,15 @@ img.invert:hover {
button#del_btn
{
background-color: transparent;
}
a#back_to_home
{
margin-left: 40px;
color: #fafafa;
font-size: 30px;
font-weight: 400;
font-style:normal;
font-family: "Roboto", helvetica, arial, sans-serif;
text-shadow: -1px -1px 1px rgba(0, 0, 0, 0.1);
text-transform:uppercase;
}

0 comments on commit c47e423

Please sign in to comment.