Problems making a search page
Moderator: General Moderators
Problems making a search page
I am having all kinds of problems making a search page for my md5 db. What I need is when a user puts in the md5 hash it will then take the first 2 characters from the hash and that is the table name. Then make the search string the hash minus the first 2 characters. Then search for the hash in the db with the table that it got from the hash to find a match then display the full hash and the plaintext form of it from the table.
I created the tables like this hash VARCHAR(30) BINARY NOT NULL, text TEXT, PRIMARY KEY(hash) TYPE=MYISAM
Every page I have found or tried to make will not do anything it seems. Can someone plz help me out.
I created the tables like this hash VARCHAR(30) BINARY NOT NULL, text TEXT, PRIMARY KEY(hash) TYPE=MYISAM
Every page I have found or tried to make will not do anything it seems. Can someone plz help me out.
well it is going to end up having over 100 million entries. This is the search page I made but it does not work. Maybe someone can find the problem in it or something
I know there is stuff wrong in there. I have made 3 completely different search pages and none of them seem to work.
Code: Select all
<html>
<head>
<title>MD5 Hash Results</title>
</head>
<body>
<h1>MD5 Hash Results</h1>
<?
trim($searchterm);
$table=substr($searchterm,0,2);
$searchterm=substr($searchterm,2,30);
$searchterm=addslashes($searchterm);
$db=mysql_connect("host", "user", "pass");
if (!db)
{
echo "Error: Could not connect to database.";
exit;
}
mysql_select_db("md5");
$query = "select * from md5 where ".$table." like '%".$searchterm."%'";
$result = mysql_query($query);
$num_results=mysql_num_rows($result);
echo "<p>Number of hashes found: ".$num_results."</p>";
for ($i=0; $i <$num_results; $i++)
{
$row=mysql_fetch_array($result);
echo "<p>".($i+1).". Hash: ";
echo htmlspecialchars( stripslashes($row["hash"]));
echo htmlspecialchars( stripslashes($row["text"]));
echo "</p>;
}
?>
</body>
</html>ok I changed it to this
$table should be the first 2 characters of the hash. although this still don't work and for some reason I am getting an $end unexpected end of file in my error log for apache.
Also I am not sure if it is grabbing the value from the form. Here is the code for the form.
I am sure I am just messed up here somewhere.
Code: Select all
$query = "select * from ".$table." where hash like '%".$searchterm."%'";Also I am not sure if it is grabbing the value from the form. Here is the code for the form.
Code: Select all
<html>
<head>
<title>MD5 Hash Lookup</title>
</head>
<body>
<h1>MD5 Hash Lookup</h1>
<form action="results.php" method="post">
<br>
Enter MD5 Hash:<br>
<input name="searchterm" type=text>
<br>
<input type=submit value="search">
</form>
</body>
</html>ok I have it now. This is my new search page and it works perfect.
Thanks guys.
Code: Select all
<?php
$mysql = mysql_connect("localhost","root","password");
$database = "MD5";
if($_GET["search"] == "on") {
$hash = strtolower($_POST["hash"]);
if(strlen($hash) == "32") {
for($i=0; $i<strlen($hash); $i++) {
$character = substr($hash,$i,1);
for($ii=0; $ii<16; $ii++) {
if(dechex($ii) == $character)
{
$checkscore[$i] = "pass";
}
}
}
if(count($checkscore) != strlen($hash)) {
$_result = "Not a valid MD5 hash."; $hash = "";
} else {
$q = "SELECT text FROM `".substr($hash,0,2)."` WHERE
hash='".substr($hash,2,30)."' LIMIT 1";
$result = mysql_db_query($database,$q,$mysql) or die(mysql_error());
$row = mysql_fetch_array($result);
$_result = $row["text"];
}
} else {
$_result = "Not a valid MD5 hash."; $hash = "";
}
}
?>
<span>
Search the Database
<br /><br />
</span>
<form action="?category=01-2&search=on" method="post">
<input name="hash" class="text" type="text" size="60"
maxlength="32" title="Paste MD5 hash here, then click search." />
<input class="submit" type="submit" value="Search" title="Click to
search." />
</form>
<span class="no-border normal-font1-10pt">
<?
echo $hash." - ".$_result;
?>
</span>