[thelist] FPDF+sql command error

Brady Mitchell mydarb at gmail.com
Wed Oct 24 11:27:35 CDT 2007


jothi jothi wrote:
> My codes are as bellows:
> 
> $sql = "SELECT Node_ID ,Date, AVG(voltage),AVG(Temper), AVG(light),AVG(accel_x), AVG(accel_y), AVG(mag_x), AVG(mag_y), AVG(mic) from suhu where Date >'{$_POST['year']}-01-01' and Date <= '{$_POST['year']}-12-31'
> group by `Date`,Node_ID ";
> 
> Do you know where is the error?

As was mentioned, using date as a field name is not a great idea as 
that's a reserved word.

The problem appears to be incorrect quoting of your SQL query in the 
$pdf->Table line. It looks fine in the $sql var above, but you've quoted 
it differently there.

Copy the $sql var definition you've got above into the file then replace 
the $pdf->Table line with:

$pdf->Table($sql);

If it still doesn't work, do an "echo $sql" to see exactly what the SQL 
that's being executed looks like.

The best way to troubleshoot dynamic sql query generation is usually to 
look at the sql that the server is trying to execute as it will often be 
obvious what the problem is. Even if it's not obvious, it gets you a 
step closer.

Brady



More information about the thelist mailing list