Reputation: 309
I'm trying to extract data from a table in access database using odbc connection and php. I have written the code below but it gives error "Uncaught exception 'com_exception' with message 'Source: Microsoft OLE DB Provider for ODBC Drivers
Description: [Microsoft][ODBC Microsoft Access Driver] Syntax error (missing operator) in query expression 'table1.col_date"
<?php $cn = new com("ADODB.Connection");
$rs = new com("ADODB.Recordset");
$cn->open("dsn=odbcconnection");
?>
<form action = "thispage.php" method = "post">
Enter Date : <input type = "text" name = "datadate" />
<input type = "submit" name = "submit" value = "submit" />
</form>
<?php
$datadate = isset($_REQUEST['datadate']) ? $_REQUEST['datadate'] : null; ?>
<?php $sql = "select col_date, sum(qty1), sum(qty2) from table1
where table1.col_date = '".$datadate."'
group by col_date
order by col_date";
// Execute query
$rs = $cn->execute($sql);
I think there is a problem in only parameter line table1.col_date = $datadate because when I replace $datadate with static date like table1.col_date = #05/08/2012# , it displays output correctly for the date
Upvotes: 0
Views: 293
Reputation: 8818
The problem is that is either you are using query string parameters posting to the current page which are empty or you are getting confused with POST. Try the following
If you are posting to the page itself then do the following
<form action = "<?php echo $PHP_SELF; ?>" method = "post">
then change the the to the following:
$datadate = isset($_POST['datadate']) ? $_POST['datadate'] : null; ?>
Lastly make the change as previously stated
Replace the [table1.col_date]
with [table1].[col_date]
or remove the brackets completely
and try the following
<?php $sql = "select col_date, qty1, qty2 from table1 where [table].[col_date]= '".$datadate."' group by col_date order by col_date";
Upvotes: 1