Hi,

I'm trying to UPDATE a table in an Access database using PHP and ODBC. Everything works fine until i try to use a variable in the WHERE statement of the SQL query:

//define SQL query
$sql="SELECT * FROM PatientDetails WHERE TraceNumber=AD1/2005";

ideally the query will use GET to obtain the tracenumber value, i.e., WHERE TraceNumber={$_GET['id']}, but this gives me the same error::

Warning: odbc_exec(): SQL error: [Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 1., SQL state 07001 in SQLExecDirect in C:\Program Files\Apache Group\Apache2\htdocs\query.php on line 39

I've done some searching on this error and it seems it occurs when the fieldname doesn't match up with whats in the database, in the database the field name is "TraceNumber" but the SQL statement is "TraceNumber=SomeValue".

Is there any way around this problem??? Or can someone paste some more details on this error?

Thanks in advance,

Joe

    You are certain on the capitalization of the letters in "TraceNumber"?

    I would also have a go assigning the TraceNumber to a variable (such as $tracen) before the sql statement since there may be an issue with the TraceNumber having a slash in it.

    eg.
    $tracen = 'AD1/2005';
    $sql="SELECT * FROM PatientDetails WHERE TraceNumber=$tracen";

    let us know how that works for you...

      I'm positive about the capitals, i also use capital letters to denote new words when naming table fields.

      I've tried what you suggested but i still get the same error. I also took out the slash from the tracenumber value just to see what would happen, but i get the same error

        I've sorted out the problem, so for future reference it seemed to be that the TraceNumber field in the Access database was waiting for a String to be passed to it so ' ' had to be used,

        $tracen = 'AD12005';
        //define SQL query
        $sql="SELECT * FROM PatientDetails WHERE TraceNumber='$tracen' ";
        

        Thanks for the help, much appreciated,

        Joe

          Write a Reply...