php – Multi-criteria search engine problem + url rewriting-ThrowExceptions

Exception or error:

new to PHP, I am currently coding a page with a multi-criteria search form which is causing me problems.

Using the rewriting URL, I initially encountered problems getting my $ _POST information. I solved my problem by adding the [QSA] flag to my rule (first, is it okay to use $ _POST?)?

Except that I have other problems now.
1) I now have pretty “Array to string conversion” messages on the feedback of each of the IDs I request (but I do have my IDs by displaying a var_dump of my $ _POST).
2) I also have a message “Cannot modify header information – headers already sent by …” (and this is where I wonder if the flag [QSA] is really the right one).
3) My SQL request is not executed (my table is empty by displaying a var_dump of the variable in which I want to store the information requested by the request).

Here is my phtml, PHP code as well as my RewriteRule:

RewriteRule ^trouver_un_jardin$ model/frontend/trouver.php [QSA]

phtml:

<form action="trouver_un_jardin" method="POST">
                        <h2 class="py-3">Formulaire de recherche</h2>
                        <div class="form-group px-3">
                            <select name="idType[]" class="form-control my-5">
                                <?php foreach ($rechercheType as $searchType) : ?>
                                    <option <?php echo $searchType["selected"] ?> value="<?php echo $searchType["id"] ?>"><?php echo $searchType["type_de_jardin"] ?></option>
                                <?php endforeach ?>
                            </select>
                            <select name="idTaille[]" class="form-control my-5">
                                <?php foreach ($rechercheTaille as $searchTaille) : ?>
                                    <option <?php echo $searchTaille["selected"] ?> value="<?php echo $searchTaille["id"] ?>"><?php echo $searchTaille["taille"] ?></option>
                                <?php endforeach ?>
                            </select>
                            <select name="idZone[]" class="form-control my-5">
                                <?php foreach ($rechercheZone as $searchZone) : ?>
                                    <option <?php echo $searchZone["selected"] ?> value="<?php echo $searchZone["id"] ?>"><?php echo $searchZone["zone"] ?></option>
                                <?php endforeach ?>
                            </select>
                            <select name="idPrix[]" class="form-control my-5">
                                <?php foreach ($recherchePrix as $searchPrix) : ?>
                                    <option <?php echo $searchPrix["selected"] ?> value="<?php echo $searchPrix["id"] ?>"><?php echo $searchPrix["prix"] ?></option>
                                <?php endforeach ?>
                            </select>
                        </div>
                        <div class="form-group px-5">
                            <button class="btn btn-form btn-block" type="submit" name="action" value="search">Trouver</button>
                        </div>
                        <?php var_dump($_POST) ?>
                        <?php var_dump($jardins) ?>
                    </form>

php :

if (isset($_POST["action"]) && $_POST["action"] == "search") { 
$req = "SELECT jardins.id, jardins.image, jardins.alt, jardins.titre, jardins.description, jardins.prix, jardins.href FROM jardins JOIN recherche_jardin ON jardins.id = id_jardin WHERE id_recherche_type = :idType AND id_recherche_taille = :idTaille AND id_recherche_zone = :idZone AND id_recherche_prix = :idPrix";
$stm = $sqlQuery->prepare($req);
$postValue = $_POST;
unset($postValue["action"]);
$stm->execute($postValue);
$jardins = $stm->fetchall(PDO::FETCH_ASSOC);

header("location: trouver_un_jardin");

};

If you could help me solve these problems.

Thanking you in advance.

How to solve:

Leave a Reply

Your email address will not be published. Required fields are marked *