I have a search program of a mysql database that results in a table where I want to be able to resort the data by the 5 different column headers. I am stuck right now and have no idea why I receive this error message:
"Unable to perform query: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'LIKE '%$search%' AND LIKE '%$search2%' ORDER BY 'DT_STRING' ASC' at line 1"
That is what happens when I click on the DT_STRING header. Any ideas on how I can change my script to get it to work would be greatly appreciated!
Thanks a lot!
php:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<center>
<table border="1" cellpadding="5" cellspacing="0" bordercolor="#000000">
<tr>
<td width="60"><b><a href="?search=$search&search2=$search2&sortby=DT_STRING">DT_STRING</a></b></td>
<td width="100"><b><a href="?search=$search&search2=$search2&sortby=ACCOUNT">ACCOUNT</a></b></td>
<td width="30"><b><a href="?search=$search&search2=$search2&sortby=ACCOUNT_TYPE">ACCOUNT_TYPE</a></b></td>
<td width="150"><b><a href="?search=$search&search2=$search2&sortby=CLIENT_ID">CLIENT_ID</a></b></td>
<td width="150"><b><a href="?search=$search&search2=$search2&sortby=USER_ID">USER_ID</a></b></td>
</tr>
<tr>
<td>
<? $hostname = "mysql"; // The Thinkhost DB server.
$username = "root"; // The username you created for this database.
$password = ""; // The password you created for the username.
$usertable = "AUDIT"; // The name of the table you made.
$dbName = "AUDITMED"; // This is the name of the database you made.
MYSQL_CONNECT($hostname, $username, $password) OR DIE("DB connection unavailable");
@mysql_select_db( "$dbName") or die( "Unable to select database");
//error message (not found message)begins
$XX = "No Record Found, to search again please close this window";
//query details table begins
$metode = $REQUEST['metode'];
$search = $REQUEST['search'];
$metode2 = $REQUEST['metode2'];
$search2 = $REQUEST['search2'];
$sortvalues = array("DT_STRING", "ACCOUNT", "ACCOUNT_TYPE", "CLIENT_ID", "USER_ID");
if(isset($GET['sortby']) && in_array($GET['sortby'], $sortvalues))
{
$sortby = $_GET['sortby'];
}
else
{
$sortby = "DT_STRING";
}
//$query = mysql_query("SELECT * FROM AUDIT WHERE $metode LIKE '%$search%' AND $metode2 LIKE '%$search2%' ORDER BY $sortby ASC")
// or die("Unable to perform query: " . mysql_error());
$query = mysql_query("SELECT * FROM AUDIT WHERE $metode LIKE '%$search%' AND $metode2 LIKE '%$search2%' ORDER BY '$sortby' ASC")
or die("Unable to perform query: " . mysql_error());
if(mysql_num_rows($query) >= 1)
{
while ($row = mysql_fetch_array($query))
{
$variable1=$row["DT_STRING"];
$variable2=$row["ACCOUNT"];
$variable3=$row["ACCOUNT_TYPE"];
$variable4=$row["CLIENT_ID"];
$variable5=$row["USER_ID"];
//table layout for results
print ("<tr>");
print ("<td>$variable1</td>");
print ("<td>$variable2</td>");
print ("<td>$variable3</td>");
print ("<td>$variable4</td>");
print ("<td>$variable5</td>");
print ("</tr>");
}
}
else
{
"Your search criterea returned no results";
}
//end
?>
</table>
</center>
Thanks again!