My PHP Store Locator Is Not Working
<p>I built a simple store locator and I setup a custom search engine to find stores by name, zip code, etc, and it works. </p>

<p>Now, I'm trying to find stores by address and return the nearest locations and distance using the haversine formula. Below is my code. Where am I going wrong?</p>

<p>When I pass the <code>$distance</code> variable to the <code>mysqli_query()</code> it tells me that it is expecting an integer. I'm probably way off.</p>

<pre><code>&lt;div class="container"&gt;
&lt;h1&gt;Store Locator&lt;/h1&gt;

&lt;div class="row"&gt;
    &lt;div class="col-xs-6"&gt;
        &lt;form action="" method="post"&gt;
            &lt;label for="search"&gt;Enter Store Name&lt;/label&gt;&lt;/br&gt;
            &lt;input type="text" name="search" value=""&gt;
            &lt;input name="submit" type="submit" name="address" class="btn btn-primary"&gt;
        &lt;/form&gt;
        &lt;?php
            if (isset($_POST['submit'])) {
                $search = $_POST['search'];
                $query = "SELECT * FROM markers WHERE zip_code LIKE '%$search%' ";
                $distance = "
                    SELECT id, 
                           (3959 * acos(cos(radians(37)) * cos(radians(lat)) * cos(radians(lng) - radians(-122)) + sin(radians(37)) * sin(radians(lat)))) 
                           AS distance 
                           FROM markers 
                           HAVING distance &lt; 25 
                           ORDER BY distance 
                           LIMIT 0 , 20
                    ";
                $search_query = mysqli_query($connection, $query, $distance);

                if (!$search_query) {
                    die("QUERY FAILED" . mysqli_error($connection));
                } else {
                    while($row = mysqli_fetch_assoc($search_query)){
                        $name = $row['name'];
                        $address = $row['address'];
                        $city = $row['city'];
                        $state = $row['state'];
                        $zip_code = $row['zip_code'];

                        echo "&lt;h4&gt;$name&lt;/h4&gt;";
                        echo "&lt;p&gt;$address&lt;/p&gt;";
                        echo "&lt;p&gt;$city, $state, $zip_code&lt;/p&gt;&lt;/br&gt;";
                    }
                }
            }
        ?&gt;
    &lt;/div&gt;
&lt;/div&gt;
</code></pre>

<p></p>