A misunderstanding I think .. I read the first post and the lines
if(empty($orders))
else if(empty($dir))
make me wonder where these variables are set initally or if they come from a form. If these two variables are get or post variables you might need to use e.g. $GET['dir'] or $POST['dir'] instead of $dir.
I think the if/else code should be modified at least to the following.
$validOrders = array('artists','titler','labeler');
if(!isset($orders) || !in_array($orders,$validOrders)) {
$orders = "artists";
}
if (!isset($dir) || empty($dir)) {
$dir = "DESC";
} else if ($dir != "DESC" && $dir != "ASC") {
$dir = "DESC";
}
// if using MySQL, use mysql_escape string
// to prevent SQL injection
$str = mysql_escape_string($str);
$sql = "SELECT * FROM records4sale WHERE artists LIKE "
."'%$str%' OR titler LIKE '%$str%' OR labeler LIKE "
."'%$str%' OR genre LIKE '%$str%' ORDER BY "
."$orders $dir"
$res = mysql_query($sql);
Besides that using "standard" single quotes around field names will produce SQL errors you can get if you do something like
$res = mysql_query($sql) or die("SQL error: ".mysql_error());
This is why I asked for any SQL errors. Either use ` or no quotes at all.
Thomas