On clicking the search button , The selected option is not getting inserted to my PHP file and hence the query is not getting executed

No response on clicking search button . Nor does the URL transfers to localhost/homeservices/searchproviders.php](https://i.stack.imgur.com/VnCiH.png) I am working on my project ,I want to transfer the selected values of city and profession to searchprovider.php file . I think the control is not getting transferred to searchprovider.php because i tried an alert script to check if it works ! But it didn’t . Can someone please help me out !! Also i have connected to mysql using PDO method .

Thanks in advance !

Here’s my index.php

<?php

include_once "./include/header.php";



$cities = ["Ahmednagar", "Akola", "Akot", "Amalner", "Ambejogai", "Amravati", "Anjangaon", "Arvi", "Aurangabad", "Bhiwandi", "Dhule", "Kalyan-Dombivali", "Ichalkaranji", "Kalyan-Dombivali", "Karjat", "Latur", "Loha", "Lonar", "Lonavla", "Mahad", "Malegaon", "Malkapur", "Mangalvedhe", "Mangrulpir", "Manjlegaon", "Manmad", "Manwath", "Mehkar", "Mhaswad", "Mira-Bhayandar", "Morshi", "Mukhed", "Mul", "Greater Mumbai*", "Murtijapur", "Nagpur", "Nanded-Waghala", "Nandgaon", "Nandura", "Nandurbar", "Narkhed", "Nashik", "Navi Mumbai", "Nawapur", "Nilanga", "Osmanabad", "Ozar", "Pachora", "Paithan", "Palghar", "Pandharkaoda", "Pandharpur", "Panvel", "Parbhani", "Parli", "Partur", "Pathardi", "Pathri", "Patur", "Pauni", "Pen", "Phaltan", "Pulgaon", "Pune", "Purna", "Pusad", "Rahuri", "Rajura", "Ramtek", "Ratnagiri", "Raver", "Risod", "Sailu", "Sangamner", "Sangli", "Sangole", "Sasvad", "Satana", "Satara", "Savner", "Sawantwadi", "Shahade", "Shegaon", "Shendurjana", "Shirdi", "Shirpur-Warwade", "Shirur", "Shrigonda", "Shrirampur", "Sillod", "Sinnar", "Solapur", "Soyagaon", "Talegaon Dabhade", "Talode", "Tasgaon", "Thane", "Tirora", "Tuljapur", "Tumsar", "Uchgaon", "Udgir", "Umarga", "Umarkhed", "Umred", "Uran", "Uran Islampur", "Vadgaon Kasba", "Vaijapur", "Vasai-Virar", "Vita", "Wadgaon Road", "Wai", "Wani", "Wardha", "Warora", "Warud", "Washim", "Yavatmal", "Yawal", "Yevla"];
?>

<h2 class="text-center" style="margin-top: 20px">Home Services</h2>
<hr>
<div class="container" style="margin-top:20px; margin-bottom: 60px;">

<form method="post" action="scripts/searchproviders.php">
    <div class="row">
        <div class="form-group col-5">
            <label for="">City</label>
            <select class="form-control" name="city" id="city">
                <option value="none">-- Select City --</option>
                <?php foreach ($cities as $city) : ?>
                <option value="<?= $city ?>"> <?= $city ?>
                </option>
                <?php endforeach; ?>
            </select>
        </div>

        <div class="form-group col-5">
            <label for="">Who's Required </label>
            <select class="form-control" name="profession" id="profession">
                <option value="none" name="profession">-- Select Profession --</option>
                <option value="electrician" name="profession">Electrician</option>
                <option value="plumber" name="profession">Plumber</option>
                <option value="mobile" name="profession">Beautician</option>
                <option value="mobile" name="profession">Maid</option>
                <option value="mobile" name="profession">Mobile Repairer</option>
                <option value="mobile" name="profession">Photographer</option>
                <option value="mobile" name="profession">Carpenter</option>
            </select>
        </div>

        <div class="form-group col-2">
            <label for="">Action</label>
            <input type="button" id="search"  class="form-control btn btn-success" type="button" value="Search"></input>
        </div>
    </div>
</form>

    <div class="table-responsive">
        <table id="providers" class="table">
            <thead>
                <tr>
                    
                    <th>Name</th>
                    <th>Address</th>
                    <th>Profession</th>
                    <th>Action</th>
                </tr>
            </thead>
            <tbody>
                <tr>
                    <td colspan='5'>Select city and profession..</td>
                </tr>
            </tbody>
        </table>
    </div>
</div>



<?php include_once "./include/footer.php";?>

Heres my searchproviders.php

<!doctype html>
<html>

<?php

require_once 'helpers.php';
echo'<script>alert("Hiii")</script>';
if (isset($_POST['city']) && isset($_POST['profession'])) {
    
    
    $city = $_POST['city'];
    $profession = $_POST['profession'];
    $servername ="localhost";
    $username ="root";
    $password ="sarasaeed";
    $dbname="services";
            
    try {
        $conn = new PDO('mysql:host=localhost;dbname=services; charset=utf8','root','sarasaeed');
        $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
        $sql = "SELECT * FROM providers WHERE city='$city' AND profession='$profession'";
        $statement = $conn->prepare($sql);  
        $statement->execute();  
        $providers = $statement->fetchAll();
        if($providers){
            foreach($providers as $key=>$value) {
                echo "<html>";
                echo "<div class='table-responsive'>";
                echo "<tr>";
                echo "<td>$providers->name</td>"."<td>$providers->adder1</td>"."<td>$providers->profession</td"."<td><a href='booking.php?provider=></td>";
            }
        }else{
            echo"NO PROVIDERS FOUND";
        }
    }catch(PDOException $e) {
                echo "Connection failed: " . $e->getMessage();
                $conn = null;
            }
}
?>
</html>
    

Change your input element’s type to submit.

1 Like

Thank You so much ! But i want the results of the query to be presented on same page as shown in that image i.e localhost/homeservices/

You will need to use JavaScript for that.

You can also use fetch to post data.