dmilani
04-22-2007, 03:07 PM
IS it possible to have a variable/string denoting the column in a search expression?
For instance:
<?php
ini_set ("display_errors", "1");
include 'config.php';
include 'opendb.php';
$tabsel = $HTTP_POST_VARS['tabsel'];
$sess = $_HTTP_POST_VARS['session'];
$sorttab = $_GET['sorttab'];
$sortvar = $_GET['sortvar'];
if (empty($sortvar)) {
$sortvar= 'tname' ;
}
if (empty($tabsel)) {
$tabsel= $sorttab ;
}
$query = "SELECT tname, contact, email, reqdiv, day, eve, cell, misc, date FROM $tabsel WHERE $sess = 'yes' ORDER BY '$sortvar' ASC";
Echoing my query reports this:
SELECT tname, contact, email, reqdiv, day, eve, cell, misc, date FROM HSG_Reg06 WHERE = 'yes' ORDER BY 'tname' ASC
Query failed: 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 '= 'yes' ORDER BY 'tname' ASC' at line 1
I am confused because $tabsel is replaced as expected but $sess is blank.
For instance:
<?php
ini_set ("display_errors", "1");
include 'config.php';
include 'opendb.php';
$tabsel = $HTTP_POST_VARS['tabsel'];
$sess = $_HTTP_POST_VARS['session'];
$sorttab = $_GET['sorttab'];
$sortvar = $_GET['sortvar'];
if (empty($sortvar)) {
$sortvar= 'tname' ;
}
if (empty($tabsel)) {
$tabsel= $sorttab ;
}
$query = "SELECT tname, contact, email, reqdiv, day, eve, cell, misc, date FROM $tabsel WHERE $sess = 'yes' ORDER BY '$sortvar' ASC";
Echoing my query reports this:
SELECT tname, contact, email, reqdiv, day, eve, cell, misc, date FROM HSG_Reg06 WHERE = 'yes' ORDER BY 'tname' ASC
Query failed: 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 '= 'yes' ORDER BY 'tname' ASC' at line 1
I am confused because $tabsel is replaced as expected but $sess is blank.