Database Search Script Help 08-30-2014, 04:14 AM
#1
Code:
<?php
global $headerinclude, $header, $theme, $footer, $templates, $lang, $user;
//Capture search and remove pointless spaces...
$searchTerm1 = trim($_GET['keyname1']);
$searchTerm2 = trim($_GET['keyname2']);
//Make sure that they are searching, and for only one thing...
if (empty($searchTerm1) && empty($searchTerm2))
{
$information = "Enter the username or email you are searching for.";
}
elseif (!empty($searchTerm1) && !empty($searchTerm2))
{
$information = "You entered both a username and email. You may only search for one at a time.";
}
else
{
//Database information...
$host = "[snip]"; //server
$db = "[snip]"; //database name
$user = "[snip]"; //database user name
$pwd = "[snip]"; //password
//Connect to server and create link to database...
$link = mysqli_connect($host, $user, $pwd, $db);
//Define query, based on which searchTerm isn't empty...
if ((!empty($searchTerm1)) && (empty($searchTerm2)))
{
$query = "SELECT * FROM mybb_users WHERE username LIKE '%$searchTerm1%'";
}
elseif (empty($searchTerm1) && !empty($searchTerm2))
{
$query = "SELECT * FROM mybb_users WHERE email LIKE '%$searchTerm2%'";
}
$results = mysqli_query($link, $query);
// Check for matching results...
if(mysqli_num_rows($results) >= 1)
{
$output = "";
while($row = mysqli_fetch_array($results))
{
$output .= "<p>" . "Username: " . $row['username'] . "<br />";
$output .= "Email: " . $row['email'] . "<br />";
$output .= "Password: " . $row['password'] . "<br />";
$output .= "Salt: " . $row['salt'] . "<br />";
$output .= "Last Used: " . gmdate("m-d-y", $row['lastvisit']) . "<br />";
$output .= "Description: " . $row['origin'] . "</p>";
}
echo $output;
}
else
{
$information = "There were no matching entries for the username or email you provided.";
}
}
$template = '<html>
<head>
<title>' . $pages['name'] . '</title>
{$headerinclude}
</head>
<body>
{$header}
{$errors}
<table class="tborder" border="0" cellspacing="0" cellpadding="5">
<tr>
<td class="thead" width="100%" colspan="2"><strong>Upgrade</strong></td>
</tr>
<tr>
<td class="trow1">
$information
</td>
</tr>
</table>
{$footer}
</body>
</html>';
$template = str_replace("\'", "'", addslashes($template));
add_breadcrumb($pages['name']);
eval("\$page = \"" . $template . "\";");
output_page($page);
?>Was making a page within Page Manager to allow people to search a database (not Sinisterly's!). Was curious if there was a way to display $output as $information, rather than echo it.












![[Image: 7ajmN5P.jpg]](https://i.imgur.com/7ajmN5P.jpg)
![[+]](https://sinister.li/images/modern/collapse_collapsed.png)


















![[Image: CDUAq9d.png]](http://i.imgur.com/CDUAq9d.png)