PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
<html>
<body>
<h2>Search</h2>
<form name="search" method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
Seach for: <input type="text" name="find" /> in
<Select NAME="field">
<Option VALUE="name"> Name</option>
<Option VALUE="address">Address</option>
<Option VALUE="telephoneno">Telephoneno</option>
</Select>
<input type="hidden" name="searching" value="yes" />
<input type="submit" name="search" value="Search" />
</form>
<?php error_reporting (E_ALL ^ E_NOTICE); ?>
<?php include 'config.php'; ?><!-- DB connection -->
<?php
$find = strtoupper(strip_tags(trim($find)));
if(isset($_POST['search']))
{
$find= $_POST['find'];
echo "<h2>Results</h2><p>";
//If they did not enter a search term we give them an error
if ($find == "")
{
echo "<p>You forgot to enter a search term";
exit;
}
$data = mysql_query("SELECT * FROM customers WHERE upper($field) LIKE'%$find%'")or die(mysql_error());
while($result = mysql_fetch_array( $data ))
{
echo $result['name'];
echo " ";
echo $result['address'];
echo "<br>";
echo $result['telephoneno'];
echo "<br>";
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>";
}
//And we remind them what they searched for
echo "<b>Searched For:</b> " .$find;
}
?>
</body>
</html>
<html>
<body>
<h2>Search</h2>
<form name="search" method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
Seach for: <input type="text" name="find" /> in
<Select NAME="field">
<Option VALUE="name"> Name</option>
<Option VALUE="address">Address</option>
<Option VALUE="telephoneno">Telephoneno</option>
</Select>
<input type="hidden" name="searching" value="yes" />
<input type="submit" name="search" value="Search" />
</form>
<?php error_reporting (E_ALL ^ E_NOTICE); ?>
<?php include 'config.php'; ?><!-- DB connection -->
<?php
$find = strtoupper(strip_tags(trim($find)));
if(isset($_POST['search']))
{
$find= $_POST['find'];
echo "<h2>Results</h2><p>";
//If they did not enter a search term we give them an error
if ($find == "")
{
echo "<p>You forgot to enter a search term";
exit;
}
$data = mysql_query("SELECT * FROM customers WHERE upper(".$field.") LIKE'%$find%'")or die(mysql_error());
while($result = mysql_fetch_array( $data ))
{
echo $result['name'];
echo " ";
echo $result['address'];
echo "<br>";
echo $result['telephoneno'];
echo "<br>";
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>";
}
//And we remind them what they searched for
echo "<b>Searched For:</b> " .$find;
}
?>
</body>
</html>