Hi, I'm trying to create a php form which checks the entered text in the database and displays it..
Code:
<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
Code:
<?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..