sql - JOIN not working with PHP + ODBC + Microsoft Access

739

I am trying to write a PHP script that plugs into an existing Access Database. If I would be starting from scratch, I would have used MySQL for the job, but because there is an existing MS Access application I am stuck with the database as it is.

As of right now, I am trying to get the following PHP Code to work.

$conn=odbc_connect('buju','','');
if (!$conn)
{
  exit("Connection Failed: " . $conn);
}

$sql="SELECT * 
      FROM Teilnehmer 
      INNER JOIN TeilnWerte ON Teilnehmer.LfdNr = TeilnWerte.Teilnehmer 
      WHERE Teilnehmer.Klasse = '$_POST[klasse]'";
$rs=odbc_exec($conn,$sql);

echo "\nErrorCode:\n".odbc_error($conn);
echo "\nErrorMessage:\n".odbc_errormsg($conn);

I am pretty sure, that the problem is in the SQL Query, since it all works fine if I only do

SELECT * FROM Teilnehmer WHERE Klasse = '$_POST[klasse]' 

without trying to join the second table.

I am using odbc and the Microsoft Access Driver. The Error Code that I get is07001. The Error Message is

[Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 1.

I have also tried

SELECT * 
FROM Teilnehmer, TeilnWerte 
WHERE Teilnehmer.LfdNr = TeilnWerte.Teilnehmer 
  AND Teilnehmer.Klasse = '$_POST[klasse]'

which did not work either.

Is there anything that I am doing wrong? Are there certain SQL commands that don't work

198

Answer

Solution:

Sinceecho $sql gives you ...

SELECT *
FROM
    Teilnehmer
    INNER JOIN TeilnWerte
    ON Teilnehmer.LfdNr = TeilnWerte.Teilnehmer
WHERE Teilnehmer.Klasse = '06A'

Test that same statement as a new query in Access. Create a query in the query designer, switch to SQL View, paste in the statement and see what happens when you run it.

Most often the cause of "Too few parameters" is a misspelled item (object name, function or SQL keyword). Since the db engine can't find that item, it assumes the item is a parameter. Access will pop up a parameter dialog asking you to supply a parameter value, and that dialog also contains the parameter's name. So it tells you which is the misspelled item.

People are also looking for solutions to the problem: php - Adding numerous checkboxes to mySQL table

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.