View Full Version : Run a search query from MS Access using PHP


suba_ri
04-23-2009, 07:10 AM
Hi, I'm trying to create a php form which checks the entered text in the database and displays it..
<html>
<head></head>
<body>
<form name="Pretraga" action="pretraga.php" method="post">
<input type="text" name="pretraga">
<input type="submit" value="Traži">
</form>
</body>
</html>- this is a simple form in which I enter text I would like to search


<?php
$pretraga=$_REQUEST['pretraga'];
require_once("connection.php");
$cur=odbc_exec($cnx,"SELECT Osobe.ID, Osobe.ImePrezime, Osobe.Slika, Osobe.BrSobe FROM Osobe WHERE
(((Osobe.ImePrezime) Like \"*\" & \"".$pretraga."\" & \"*\"));");
if (!$cur) {
Error_handler( "Error in odbc_exec( no cursor returned ) " , $cnx );
}
echo "<table border=0><tr><td>ID</td><td>Ime i prezime</td><td>Slika</td><td>Broj sobe</td></tr>";
while(odbc_fetch_row($cur)){
$ID=odbc_fetch_row($cur,1);
$ImePrezime=odbc_fetch_row($cur,2);
$Slika=odbc_fetch_row($cur,3);
$BrSobe=odbc_fetch_row($cur,4);

echo "<tr><td>$ID</td><td>ImePrezime</td><td><img src=\"".$Slika."\"</td><td>$BrSobe</td></tr>";
}
echo "</table>";
odbc_close($cnx);

?>
- and this is the form that should connect to the database and search for entered text.

I get an error saying:
Warning: odbc_exec() [function.odbc-exec (http://localhost/access/function.odbc-exec)]: SQL error: [Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 2., SQL state 07001 in SQLExecDirect in C:\xampp\htdocs\access\pretraga.php on line 5

Fatal error: Call to undefined function error_handler() in C:\xampp\htdocs\access\pretraga.php on line 7The query works perfectly in Access, only difference is that instead of SELECT Osobe.ID, Osobe.ImePrezime, Osobe.Slika, Osobe.BrSobe FROM Osobe WHERE
(((Osobe.ImePrezime) Like \"*\" & \"".$pretraga."\" & \"*\"));");
I have [insert text you would like to search] and it displays text box in which I enter the text..

Hope you understood my question..
Thanks in advance for any help..

suba_ri
04-26-2009, 01:03 PM
I've tried using single quotes ( ' ) in the query instead the normal ones " and still nothing..
Query will work when I leave out the "*" parts, but then I can only find records in database if I know the whole record exactly and that's not the point of a search engine :D

Can someone please help, I should finish my project in the following week, and I've tried to google this problem, but I had no luck in finding answer because MS Access is rarely used with php :(