Page 1 of 1

Combining conditions (session variables) in WHERE clause

Posted: Mon Oct 06, 2008 3:52 am
by joeltonnberg
Hi,

I'm trying to filter a query using two session variables, however all I get is "Query was empty".

Here is my code:

Code: Select all

$colname1 = "-1";
if (isset($_SESSION['Session1'])) {
  $colname1 = $_SESSION['Session1'];
}
  $colname2 = "-1";
if (isset($_SESSION['Session2'])) {
  $colname2 = $_SESSION['Session2'];
}
mysql_select_db("database");
$query_Result = sprintf("SELECT * FROM Table WHERE Variable1 = %s AND Variable2 = %s", GetSQLValueString($colname1, "text", $colname2, "text"));
$Result = mysql_query($query_Result) or die(mysql_error());
$row_Result = mysql_fetch_assoc($Result);
$totalRows_Result = mysql_num_rows($Result);
?>

Re: Combining conditions (session variables) in WHERE clause

Posted: Mon Oct 06, 2008 3:56 am
by PietM
Doesn't the function GetSQLValueString return one value? If that's the case, then your query will never have a value for the second %s.

Re: Combining conditions (session variables) in WHERE clause

Posted: Mon Oct 06, 2008 4:18 am
by joeltonnberg
that's right, thanks! I added a second GetSQLValueString and it works fine :)