Run a search query from MS Access using PHP (1 Viewer)

suba_ri

New member
Local time
Yesterday, 18:28
Joined
Apr 22, 2009
Messages
6
Hi, I'm trying to create a php form which checks the entered text in the database and displays it..
PHP:
<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:
<?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]: 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 7
The 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

New member
Local time
Yesterday, 18:28
Joined
Apr 22, 2009
Messages
6
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 :(
 

Users who are viewing this thread

Top Bottom