I have a form that looks something like this:

<input name="company" value="company1" />
<input name="company" value="company2" />
<input name="company" value="company3" />

I need to come up with a way to search a mysql table based off what checkboxes a user checks. Keep in mind there can be multiple companies selected.

For example

SELECT * FROM Companies WHERE CompanyName = $companies

My issue is I don't know how to combine the post array of company names to correctly query it.

Any help would be appreciated, thanks!

Member Avatar for Rahul47

It should be soemthing like this:

if(isset($_POST['submit']) && !empty($_POST['submit']))
        {
            $cname=$_POST['company'];
            $query="select * from company where name='$cname'";
            $result=mysqli_query($con,$query);
                while($row = mysql_fetch_array($result))
                {
                    echo "Company Names <br>";
                    echo $row['name'];   
                }
        }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.