First of all, I had to create a form which looks like this –

Code for that looks like this –

I put it in div because I wanted to customize it in CSS later on.
Explanation of the code
I created a form and chosen post as I wanted it to post information to different file that I’ve created called ‘search.php’. This is set up by ‘action=”search.php” ‘.
Then I created select option and added two options for users to choose from which was ‘Name’ and Description’.

To create a variable so we can work with it later, I needed to change the name of it so I know which one it is. It is always the one with saying ‘name’.

Then I created field to type in.

Again, I created a variable called ‘search’ by changing ‘name’ and also I set maximal limit of characters to 30. It is because I set up VARCHAR data type in tables to 30. I could decide if I wanted it to be a password type where users would see only ‘*’ instead of full characters or two other types. I went for standard type as it is search box.

Last thing I had to create was submit button. 

I created variables with a function ‘post’ as I wanted it to sent everything that is written and selected in form sending to database.

By the code bellow, I set it up to condition ‘if search bar is empty, echo out You did not enter a search term, please try again.’


Then I created switch which means ‘from whichever selected option, if it is selected ‘Name’ it’ll go to table ‘PhotosTable’ and select information from row ‘Name’ and store it in a variable called $QuerySelect. Creating another variable called ‘$result’ so we can store it there. ‘mysql_query’ is used for selecting data from the table. Last code %search% (wild card) means that even if there’s something similar typed in that row, it’ll still select it. I did the same thing with Description.


Then I created loop and fetched it to another variable ‘$row’ so I could echo it out.

Depending on what users selected and written into search box, it’ll echo out the right pictures and text from tables.

The last code frees data and disconnect everything from database.
