SirTom909
04-15-2009, 01:21 PM
Hey Everyone,
Having some trouble with ereg function in my PHP script. The user should be able to query the db either by the ID number or surname, however I want to apply some patterning matching to prevent a user from querying a single number or digit and have a large number of entries returned when searching by ID.
The ID appears in four ways, "ABCD123" "ABCD12" and "AB123" "AB12" now I want a user to be able to query using any of the those four examples, however my script doesnt appear to be working, any help would be great.
<body>
<form name="search.php" method="post" action="<?=$PHP_SELF?>">
Seach for: <input type="text" name="find" /> in
<Select NAME="field">
<Option VALUE="id">ID Number</option>
<Option VALUE="surname">Surname</option>
</Select>
<input type="hidden" name="searching" value="yes" />
<input type="submit" name="search" value="Search" />
</form>
<?
if ($searching =="yes")
{
echo "<h2>Results</h2><p>";
if ($find == "")
{
echo "<p>You forgot to enter a search term";
exit;
}
mysql_connect('localhost', 'user', 'pword') or die(mysql_error());
mysql_select_db("server") or die(mysql_error());
function checkfind($find) {
$find = strtoupper(str_replace(chr(32),'',$find));
if (ereg ("^(AB)([0-9])|^(ABCD)([0-9])",$find));
return $find;
else
return FALSE;
}
$find = strip_tags($find);
$find = trim ($find);
$find = str_replace(' ','',$find);
$data = mysql_query("SELECT * FROM officers WHERE upper($field) LIKE'%$find%'");
while($result = mysql_fetch_array( $data ))
{
echo $result['id'];
echo " ";
echo $result['surname'];
echo "<br>";
echo $result['url'];
echo "<br>";
echo $result['expiry'];
echo " ";
echo "<br>";
}
$anymatches=mysql_num_rows($data);
if ($anymatches == 0)
{
echo "Sorry, but we can not find an entry to match your query<br><br>";
}
echo "<b>Searched For:</b> " .$find;
}
?>
</body>
</html>
Having some trouble with ereg function in my PHP script. The user should be able to query the db either by the ID number or surname, however I want to apply some patterning matching to prevent a user from querying a single number or digit and have a large number of entries returned when searching by ID.
The ID appears in four ways, "ABCD123" "ABCD12" and "AB123" "AB12" now I want a user to be able to query using any of the those four examples, however my script doesnt appear to be working, any help would be great.
<body>
<form name="search.php" method="post" action="<?=$PHP_SELF?>">
Seach for: <input type="text" name="find" /> in
<Select NAME="field">
<Option VALUE="id">ID Number</option>
<Option VALUE="surname">Surname</option>
</Select>
<input type="hidden" name="searching" value="yes" />
<input type="submit" name="search" value="Search" />
</form>
<?
if ($searching =="yes")
{
echo "<h2>Results</h2><p>";
if ($find == "")
{
echo "<p>You forgot to enter a search term";
exit;
}
mysql_connect('localhost', 'user', 'pword') or die(mysql_error());
mysql_select_db("server") or die(mysql_error());
function checkfind($find) {
$find = strtoupper(str_replace(chr(32),'',$find));
if (ereg ("^(AB)([0-9])|^(ABCD)([0-9])",$find));
return $find;
else
return FALSE;
}
$find = strip_tags($find);
$find = trim ($find);
$find = str_replace(' ','',$find);
$data = mysql_query("SELECT * FROM officers WHERE upper($field) LIKE'%$find%'");
while($result = mysql_fetch_array( $data ))
{
echo $result['id'];
echo " ";
echo $result['surname'];
echo "<br>";
echo $result['url'];
echo "<br>";
echo $result['expiry'];
echo " ";
echo "<br>";
}
$anymatches=mysql_num_rows($data);
if ($anymatches == 0)
{
echo "Sorry, but we can not find an entry to match your query<br><br>";
}
echo "<b>Searched For:</b> " .$find;
}
?>
</body>
</html>