Repository navigation
Expand file tree
/
Copy pathsearch.php
More file actions
60 lines (59 loc) · 1.44 KB
/
Copy pathsearch.php
File metadata and controls
60 lines (59 loc) · 1.44 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
54
55
56
57
58
59
60
<?php
session_start();
include("session.php");
?>
<html>
<head>
<title>Search</title>
</head>
<body>
<center>
<form method="GET" action="search.php">
<input type="text" name="search">
<input type="submit" name="submit" value="Search database">
</form>
</center>
<hr>
<u>Results:</u>
</body>
</html>
<?php
if(!isset($_SESSION['name'])){
echo "Access denied.";
exit;
}else{
if(isset($_REQUEST['submit'])){ //the buttom was click
mysql_connect("Localhost","thewhole_root","mexico1") or die("Can not connect rigth now. Try it later!!!");
mysql_select_db("thewhole_testsite");
$search = mysql_real_escape_string($_GET['search']);
$terms = explode(" ", $search); //makes an Array with words delimited
$query = "select * from users where ";
$i = 0;
foreach ($terms as $each) {
$i++;
if($i==1){
$query .= "name like '%$each%' ";
}else{
$query .= "or name like '%$each%' ";
}
}
$query = mysql_query($query);
$num = mysql_num_rows($query);
if($num>0 && $search !=""){
echo "$num record(s) found for <b>$search</b>!";
while($row = mysql_fetch_assoc($query)){
$id = $row['id'];
$name = $row['name'];
$email = $row['email'];
$password = $row['password'];
echo "<h3>Name: $name (id: $id)</h3>Email: $email<hr width='3%' align='left'><br/>";
}
mysql_close();
}else{
echo "No results found";
}
}else{
echo "Please type any word";
}
}
?>