el_nino Posted December 29, 2009 Share Posted December 29, 2009 hey... I have a search function which is used to search my PostgreSQL database. I have included the code below <html> <head> <title>Search</title> </head> <div align="center"> <?php include ('includes/header.html') ?> <body> <p>  </p> <p>Enter a Author or Article title to begin searching</p> <p>  </p> <form name="form" action="search.php" method="post"> <input type="text" name="q" /> <input type="submit" name="Submit" value="Search" /> </form> <p></p> <p>  </p> </body> <?php //include ('includes/footer.html') ?> </div> </html> and... <html> <head> <title>Search</title> </head> <?php include ('includes/header.html'); ?> <div align="center"> <body> <p> </p> <?php //connecting to the database include('includes/db_connect.php') ?> <?php //$sql = "select * from jfs where author ilike '%$search_author%' order by issue"; //$sql = "select* from jfs where author like '%searchstring%' order by issue"; $sql = "select * from jfs where author ilike '%$search_author%'" ; $result_set = pg_Exec ($conn, $sql); $rows = pg_NumRows($result_set); if ((!$result_set) || ($rows < 1)) { echo "<H1>ERROR - no rows returned</H1><P>"; exit; //exit the script } for ($j=0; $j < $rows; $j++) { $issue = pg_result($result_set, $j, "issue"); $page = pg_result($result_set, $j, "page"); $author = pg_result($result_set, $j, "author"); $title = pg_result($result_set, $j, "title"); $format = pg_result($result_set, $j, "format"); $url = pg_result($result_set, $j, "url"); ?> <table table border="3" width=60%> <tr><th>Issue</th><th>Page</th><th>Author</th><th>Title</th><th>Format</th><th>URL</th></tr> <TR> <TD width=10%> <?php echo "<a href=$url> $issue </a>"; ?> </TD> <TD width=10%> <?php echo "<a href=$url> $page </a>"; ?> </TD> <TD width=15%> <?php echo "<a href=$url> $author </a>"; ?> </TD> <TD> <?php echo "<a href=$url> $title </a>"; ?> </TD> <TD width=10%> <?php echo "<a href=$url> $format </a>"; ?> </TD> <TD width=30%> <?php echo "<a href=$url> $url </a>"; ?> </TD> </TR> </table> <?php } ?> <?php pg_FreeResult($result_set); pg_Close($conn); ?> </TABLE> </body> </div> <?php //include ('includes\footer.html'); ?> </html> this works in that i get a set of results when the user enters a search term and click search and do not get results when no term is entered but the problem is that no matter what term is entered into the search field the same results show up every time. help? el nino Quote Link to comment https://forums.phpfreaks.com/topic/186587-searching-a-postgresql-database/ Share on other sites More sharing options...
btherl Posted December 29, 2009 Share Posted December 29, 2009 Your form input is called "q", so you should access that with either $_POST['q'] or $_REQUEST['q'] in the code. Quote Link to comment https://forums.phpfreaks.com/topic/186587-searching-a-postgresql-database/#findComment-985416 Share on other sites More sharing options...
el_nino Posted December 29, 2009 Author Share Posted December 29, 2009 cheers Quote Link to comment https://forums.phpfreaks.com/topic/186587-searching-a-postgresql-database/#findComment-985433 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.