Hello, I have a mysql database in my website and use it with php to search through the database for a certain baseball player name entered by in the search, (it goes to results.php). I want to be able to have each players result of the search be indexed in search engines by having the field that they enter be in the variable of the url. Example: results.php?$search=Playername. However when I go to a url with a players name it spits out every player in the database and when I put in echo $sql, it doesn't have anything for the $search variable. Here is the code, can someone tell me why this isn't working?
<?
function db_connect(){
$hostname = "***";
$username = "";
$password = "";
$dbName = "**";
MYSQL_CONNECT($hostname, $username, $password) OR DIE("DB connection unavailable");
@mysql_select_db( "$dbName") or die( "Unable to select database");
}
function search_db($usertable, $search){
$metode = "Player";
$sql = 'select * from ' . $usertable . ' where ' . $metode . ' like "%' . $search . '%" limit 0, 30';
$query = mysql_query($sql) OR DIE(mysql_error());
while($row=mysql_fetch_array($query)){
$variable1=$row["Player"];
$variable2=$row["Pos"];
$variable3=$row["HR"];
$variable4=$row["RBI"];
echo $sql;
print ("<table width=80% border=0 cellspacing=0 cellpadding=0 align=center><br> //continues printing out variables in table");
}
}
db_connect();
search_db('Yankees', $POST['search']);
search_db('Anaheim', $POST['search']);
search_db('Arizona', $_POST['search']);
?>
The sql goes like this when you try and define $search in the url:
select * from Yankees where Player like "%%" limit 0, 30
And every player in the database is shown, anyone know why this is happening?