Skip to content
Advertisement

How to combine search text and checkboxes using sql bootstrap php

What I have so far: I’m working on a database based website. So far, I have a search-text-form with bootstrap and a submit button in index.php. In search.php, I get an output according to the word I typed into the search-text-form.

The Literature_table in the background looks like this:

JavaScript

I can currently search for the Author name and title in the search-text-form.

What I want to do: I want to add checkboxes under the search-text-box, where I can choose the genre. The genre is stored as a ‘set’ in the database. Now how can I add those checkboxes to the search-box-form I already have? I only want one single submit button and checking the checkboxes is optional for the search.

Codes

index.php

JavaScript

and search.php:

JavaScript

I experimented with several codes but nothing works. I also tried to resolve this by adding an ‘AND’-condition without results. I’m new to sql etc. in general and would appreciate your help!

Advertisement

Answer

You should store values from form in array. You need to change input name.

JavaScript

For select, you need to use “IN” operator.

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement