Alright, So i am trying to code a little PHP Search Script for My website so users can simply do a search from a artist name, song name or a city. My table in my database has 'city', 'artist' and 'city'.
Here is my form:
<div id="search">
<form name="search" method="post" action="../searchDb.php">
<input type="text" name="find" placeholder="What are we searching for ?"/> in
<Select NAME="field">
<Option VALUE="artist">Artist</option>
<Option VALUE="song">Song</option>
<Option VALUE="city">City</option>
</Select>
<input type="hidden" name="searching" value="yes" />
<input type="submit" name="search" value="Search" />
</form>
</div>
As you can see, there are three OPTION values (one for each column in my table). Here is my PHP code:
<?php
$searching = "searching";
$find = "find";
$field = "field";
//this is to make sure the user entered content
if ($searching =="yes")
{
echo "<p><h2>Results</h2></p>";
//if user did not enter anything in the search box, give error
if ($find == "")
{
echo "<p>You forgot to enter a search term</p>";
}
include 'connect.php';
// strip whitespace, non case sensitive
$find = strtoupper($find);
$find = strip_tags($find);
$find = trim ($find);
//perform search in specified field
$data = mysql_query("SELECT * FROM artists_table WHERE upper($field) LIKE'%$find%'");
//show results
while($result = mysql_fetch_array( $data ))
{
echo $result['artist'];
echo " ";
echo $result['song'];
echo "<br>";
echo $result['city'];
echo "<br>";
echo "<br>";
}
//counts results. ifnone. error
$anymatches=mysql_num_rows($data);
if ($anymatches == 0)
{
echo "Sorry, but we can not find an entry to match your query<br><br>";
}
//show user what he searched.
echo "<b>Searched For:</b> " .$find;
}
?>
My connect.php (that is included) works perfectly (i have that same file working on another page, no problems..So its safe to say thats not the problem).
When i do a test and run a search, it loads up my searchDb.php but NOTHING is displayed. Simply a white page...
Any help would be greatly appreciated. I am lost as to why or what is not working... Thanks Guys !
"find"tomorrow it's$_GET...$findand$field(given that they're provided by user) to prevent SQL injection.