Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7702533
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T23:14:55+00:00 2026-05-31T23:14:55+00:00

Not sure if this is against stackoverflow rules as it’s not a specific code

  • 0

Not sure if this is against stackoverflow rules as it’s not a specific code question but I really need a little help.

I want to know if it is possible to create a search feature (search box) on an HTML webpage that will query a database and return the results?

Basically I have a database of products and their related categories. A user would come to the website, enter the category in the search field…somehow query the database and return the results on a new page.

Note: the results page doesn’t have to be HTML (could be PHP etc).

If you could also include a little guidance on how (please nothing detailed, just need a direction).
Thank you!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T23:14:57+00:00Added an answer on May 31, 2026 at 11:14 pm

    Yeah, sure, that’s pretty easy.

    Here’s what I would do:

    On your first page:

    <form action="mypage.php?searching=true" method="POST">
    <input type="text" name="searchcategory" value=""/>
    <input type="submit" value="Search"/>
    </form>
    

    On mypage.php:

    <table>
    <?php
        $sql=$db->prepare('SELECT * FROM mytable WHERE category=:category');
        $sql->execute(array(':category'=>$_REQUEST[searchcategory]));
    
        while ($row=$sql->fetch())
        {
           //Here is where you will loop through all the results for your search. If 
           //you had for example for each product name, price, and category, 
           //you might do the following
           echo "<tr><td>$row[name]</td><td>$row[price]</td><td>$row[category]</td></tr>";
        }
    ?>
    </table>
    

    NOTES:

    • I use mySQL…I’m not sure how you would do it with something else, but I would guess you could adapt the code for another sort of database.

    • I generally use the PDO (accessing through prepare and execute)…my teacher said it was more secure. You can change that part of the code to however you connect to your DB. The code I use to connect looks something like (goes before the code above on mypage.php):

      try {
      $db = new PDO("mysql:host=localhost;dbname=mydatabasename","username","password");      
      } catch (Exception $e) {
      echo "PDO connection error: " . $e->getMessage();
      exit(1);
      }
      
    • They don’t actually have to be separate pages. If you had both pages php (the first one not straight HTML), you could just change the content based on whether a variable (maybe called searching) was set to true or false.

    Let me know if any of that is unclear, and I’d be happy to help you out. Good luck! 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Not sure if this question is a duplicate in need of removal, but I
Not sure this is a programming question, but we use LaTeX for all our
Not sure this is possible, but looking to write a script that would return
I'm not sure this is possible, but in ruby, you can dynamically call a
I'm not sure this is possible, but is there a syntax to be used
I'm sure this is a fairly trivial problem, but I'm not sure what to
First of all I'm not sure this is even possible, however I need to
I am not sure if this is possible but I am trying to come
I'm not sure if this is even possible, but I figured I'd ask before
I am not sure if this is possible, but I have a scenario where

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.