MySQL – SEARCH Form with HTML and PHP

You can create an HTML form that allows you to search records in your MySQL Tables and print the results in a web browser.

In these project we use LIKE and wildcards for the query so that users do not have to have an exact match for results to be provided.

Simple Search Form Project

search.html

   Search 

phpSearch.php

connect_error)< die("Connection failed: ". $conn->connect_error); > $sql = "select * from students where name like '%$search%'"; $result = $conn->query($sql); if ($result->num_rows > 0)< while($row = $result->fetch_assoc() )< echo $row["name"]." ".$row["age"]." ".$row["gender"]."
"; > > else < echo "0 records"; >$conn->close(); ?>

Option Box Search Form Project

searchoption.html

   Search  
Column:

phpSearchOption.php

connect_error)< die("Connection failed: ". $conn->connect_error); > $sql = "select * from students where $column like '%$search%'"; $result = $conn->query($sql); if ($result->num_rows > 0)< while($row = $result->fetch_assoc() )< echo $row["name"]." ".$row["age"]." ".$row["gender"]."
"; > > else < echo "0 records"; >$conn->close(); ?>

Related Articles

MySQL – Table Joins Introduction (inner join)

Joining Tables allows you to interact with two tables as if they are one. This means you can simply reference a record from one table in another such as having a PART record reference a […]

HTML Programming – Introduction

PHP Project (Simple) – Dynamic Photo Gallery Stream

Using the GLOB function in PHP you can put all of the file names on a folder, and then print them out with additional HTML to create a Dynamic Photo Stream. In this project the […]

Be the first to comment

Leave a Reply Cancel reply

You must be logged in to post a comment.

DONATE

If you want to tip a few dollars for the education videos.