Query question

I’ve a huge database sorting out different quantities of records, comics, cards, etc. I would like to be able to query the database and have the form work if I enter one of three search terms, or all three. Currently, it worked with all three, but setting it up for reading only one search term, or two search terms seems to be my headache.

[php]$sql = "select * from Cards.Twins where ";
if (isset($_POST[‘LastName’]))
$sql .= “LastName = ‘{$_POST[‘LastName’]}’”;
else if (isset($_POST[‘Company’]) && isset($_POST[‘LastName’]))
$sql .= “and Company = ‘{$_POST[‘Company’]}’”;
else if (isset($_POST[‘Year’]) && (isset($_POST[‘LastName’]) || isset($_POST[‘Company’]))
$sql .= “and Year = ‘{$_POST[‘Year’]}’”;

if (!isset($_POST[‘LastName’]) && !isset($_POST[‘Year’]))
$sql .= “Company = ‘{$_POST[‘Company’]}’”;
if (!isset($_POST[‘LastName’]) && !isset($_POST[‘Company’]))
$sql .= “Year = ‘{$_POST[‘Year’]}’”;
$result = mysql_query($sql) or die(mysql_error());
$row = mysql_fetch_assoc($result);[/php]

This is what I was recommended by a friend, but this parse errors. I was reading from the php website that:

isset() only works with variables as passing anything else will result in a parse error. For checking if constants are set use the defined() function.
could this be the issue? that isset is trying to read sql, and a POST variable?
Sponsor our Newsletter | Privacy Policy | Terms of Service