Help With Searching A Database Using Php

Need to search depending on text input

Page 1 of 1

5 Replies - 2990 Views - Last Post: 04 February 2005 - 08:35 AM Rate Topic: -----

#1 bexlhoward1  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 40
  • Joined: 04-February 05

Help With Searching A Database Using Php

Posted 04 February 2005 - 08:09 AM

Hi, I am now to PHP and probably have a very simple question.

All I want to do is display results from an Access database depending on what the user has entered in a text box e.g.

If the user has entered 'Preece' as an author, I want books written by Preece to be displayed:

$criteria=$_REQUEST['criteria']; //criteria is a drop down list with either Author, title or ISBN
$textinput=$_REQUEST['textinput']; //textinput is the text input box


if($criteria!=null)
{
switch($criteria)
{
case"Author":$strSQL="SELECT Title, ISBN, Author, Year FROM catalogue ORDER BY [title] WHERE Author = '". $textinput. "'";break;


}
}

I get the following error:
Warning: (null)(): Invoke() failed: Exception occurred. Source: Microsoft OLE DB Provider for ODBC Drivers Description: [Microsoft][ODBC Microsoft Access Driver]General error Unable to open registry key 'Temporary (volatile) Jet DSN for process 0x158c Thread 0x1214 DBC 0xbf6304 Jet'. in e:\webareas\hr112\cmslibs\html\results.php on line 137

I presume I have written something wrong in the SQL statement. Any help pleae!

Thanks

Bex,

Is This A Good Question/Topic? 0
  • +

Replies To: Help With Searching A Database Using Php

#2 Amadeus  Icon User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 248
  • View blog
  • Posts: 13,506
  • Joined: 12-July 02

Re: Help With Searching A Database Using Php

Posted 04 February 2005 - 08:13 AM

Is your Access database open (on your machine) while you're running this code? Access often has problems with pages accessing it when open.
Was This Post Helpful? 0
  • +
  • -

#3 bexlhoward1  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 40
  • Joined: 04-February 05

Re: Help With Searching A Database Using Php

Posted 04 February 2005 - 08:17 AM

No its not open, I think the problem is with this line:

$strSQL="SELECT Title, ISBN, Author, Year FROM catalogue ORDER BY [title] WHERE Author = '". $textinput. "'";break;

As this error talks about a missing oporater:
Warning: (null)(): Invoke() failed: Exception occurred. Source: Microsoft OLE DB Provider for ODBC Drivers Description: [Microsoft][ODBC Microsoft Access Driver] Syntax error (missing operator) in query expression '[title] WHERE status = new'. in e:\webareas\hr112\cmslibs\html\new.php on line 122

What do you think?

Thanks
Was This Post Helpful? 0
  • +
  • -

#4 Amadeus  Icon User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 248
  • View blog
  • Posts: 13,506
  • Joined: 12-July 02

Re: Help With Searching A Database Using Php

Posted 04 February 2005 - 08:25 AM

Well, that second error is different than the first one...is it the second one you've got a problem with?

the error itself: that is an SQL error...you have Title (the column name) both capiltalized and not, and the ORDER BY clause should be after the WHERE clause.
Was This Post Helpful? 0
  • +
  • -

#5 bexlhoward1  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 40
  • Joined: 04-February 05

Re: Help With Searching A Database Using Php

Posted 04 February 2005 - 08:30 AM

Yes that was it! I moved the Order by after the where and it now works fine!

Thanks you so much!

Rebecca.
Was This Post Helpful? 0
  • +
  • -

#6 Amadeus  Icon User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 248
  • View blog
  • Posts: 13,506
  • Joined: 12-July 02

Re: Help With Searching A Database Using Php

Posted 04 February 2005 - 08:35 AM

No problem...have a great day.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1