0
votes
$att="select AttData.Rollno,AttData.Name,AttData.Year,AttData.sec,
        AttData.".$date." 
  from AttData where AttData.sec='".$sec."' 
    and AttData.dept='".$dept."' 
    and  AttData.year='".$year."' and AttData.".$date."='AB'  ";

I am trying to select absents data from AttData table with dynamic column value as date variable .

But i am getting following error :

Warning: odbc_exec(): SQL error: [Microsoft][ODBC Microsoft Access Driver] Invalid use of '.', '!', or '()'. in query expression 'AttData.'02-07-2016'., SQL state 37000 in SQLExecDirect in C:\xampp\htdocs\sms\repotdaygen_allyear.php on line 325 select invalid37000

Please help me what is the error.

2
use date_column_name from the table instead of value $date - jitendrapurohit

2 Answers

0
votes

try this

$att="select AttData.Rollno,AttData.Name,AttData.Year,AttData.sec,AttData.{$date} from AttData where AttData.sec='{$sec}' and AttData.dept='{$dept}' and AttData.year='{$year}' and AttData.{$date}='AB' ";

i hope it will be helpful

0
votes

If a string is enclosed in double-quotes ("), PHP will interpret the variables. So try this:

$att="select AttData.Rollno,AttData.Name,AttData.Year,AttData.sec,AttData.$date from AttData where AttData.sec='$sec' and AttData.dept='$dept' and AttData.year='$year' and AttData.$date='AB' ";

In addition, use braces to ensure PHP doesn't miss the variables when they are followed by other chars:

$att="select AttData.Rollno,AttData.Name,AttData.Year,AttData.sec,AttData.{$date} from AttData where AttData.sec='{$sec}' and AttData.dept='{$dept}' and AttData.year='{$year}' and AttData.{$date}='AB' ";