HighDots Forums  

filter recordset with two criteria (PHP/MySQL)

Macromedia Dreamweaver Macromedia Dreamweaver Discussions (macromedia.dreamweaver)


Discuss filter recordset with two criteria (PHP/MySQL) in the Macromedia Dreamweaver forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
gypsysteve
 
Posts: n/a

Default 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.





Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.