filter recordset with two criteria (PHP/MySQL) -
11-11-2004
, 08:49 AM
I am trying to filter a recordset using two possible criteria selections - a
dealercode (number) or a dealername (string).
Users can either enter a dealercode i.e 12345 - this returns one record for
the dealercode 12345 or the user can
enter a dealername i.e 'armstrongs' and get a list of possible dealers called
'armstrongs'.
When I test the page - entering a dealercode works OK and displays the correct
record.
When I enter a dealername I get an error -
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 'OR DealerName LIKE
(' ') ORDER BY DealerCode ASC' at line 1
Code -
$colname1_rstDealerList = "";
if (isset($_POST['txtdealername'])) {
$colname1_rstDealerList = (get_magic_quotes_gpc()) ? $_POST['txtdealername']
: addslashes($_POST['txtdealername']);
}
$colname_rstDealerList = "0";
if (isset($_POST['txtdealercode'])) {
$colname_rstDealerList = (get_magic_quotes_gpc()) ? $_POST['txtdealercode']
: addslashes($_POST['txtdealercode']);
}
mysql_select_db($database_FleetConn, $FleetConn);
$query_rstDealerList = sprintf("SELECT DealerCode, DealerName, Telephone FROM
dealer_tbl WHERE DealerCode = %s OR DealerName LIKE ('%s') ORDER BY DealerCode
ASC", $colname_rstDealerList,$colname1_rstDealerList);
$rstDealerList = mysql_query($query_rstDealerList, $FleetConn) or
die(mysql_error());
$row_rstDealerList = mysql_fetch_assoc($rstDealerList);
$totalRows_rstDealerList = mysql_num_rows($rstDealerList);
Can anybody please advise. |