Building a Custom Search Engine using PHP and MySQL

Technologies used: PHP, HTML, MySQL, phpMyAdmin, Windows 10

Create Search Engine Form in HTML

HTML code for index.html
HTML code for index.html
index.html code
  • method=get” — the GET method type is what will take the text entered into the text box and throw it into the url for the user.
  • input type=text” — the “text” type is simply going to do that, make the input a text input.
  • name=search” — the “name” can be whatever you want it to be.
  • input type=submit” — the “submit” type makes the form submit the search input to the script.

Create Search Engine Database (using MySQL/phpMyAdmin)

Next we will setup the back-end SQL database. Since our search engine is pretty simple, our MySQL database will also be simple. Just a few fields to store our data. To create the database and table, I will be using phpMyAdmin to manage the MySQL database backend. To learn more about Apache, MySQL and PHP setup, click here.

vendors table & attributes

Get Search Engine Keyword

Connect to MySQL Database and Process Query

Next, connect to MySQL using the mysqli_connect function. The function will connect you to the database of your choice. Then, run the query string against the database. We also get the number of rows returned from doing so. Using the number of rows, you can use conditionals to determine if you have search results to display to the user.

Display Search Engine Results to User

Using the Search Engine

Finally, let’s try using our search engine! I want to search for Gucci products so I typed in “gucci” and here are my results:

Computer Science major at UT Dallas. Interested in data science, business intelligence and programming.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store