Bonjour à tous,
Je suis débutant en php et je développe pour un projet professionnel un outil de recherche.
L'idée est la suivante : L'utilisateur saisie via un formulaire HTML un ou plusieurs champs, et suivant les champs qu'il à rempli, le php va chercher dans la base SQL selon les critères saisies.
Le code HTML qui me permet la saisie est la suivant :
<center>
<fieldset>
<legend>Recherche dans la base de reporting et export</legend>
<p>
<form method="post" action="rechercheBaseReporting.php">
<p>
<label for="starting_point"> Point de départ :</label>
<input type="text" name="starting_point" id="starting_point">
</p>
<p>
<label for="arrival_point"> Point d'arrivée :</label>
<input type="text" name="arrival_point" id="arrival_point"><br>
</p>
<p>
<label for="api_pallet_code"> ID unique palette :</label>
<input type="text" name="api_pallet_code" id="api_pallet_code"><br>
</p>
<p>
<label for="schneider_pallet_reference"> Réference palette SCHNEIDER :</label>
<input type="text" name="schneider_pallet_reference" id="schneider_pallet_reference"><br>
</p>
<p>
<label for="format_pallet"> Format palette :</label>
<select name="format_pallet" id="format_pallet">
<option value="ALL" selected>ALL</option>
<option value="P06">P06</option>
<option value="P10">P10</option>
<option value="P12">P12</option>
</select>
</p>
<p>
<label for="process_status"> Statut process :</label>
<select name="process_status" id="process_status">
<option value="ALL" selected>ALL</option>
<option value="reception_de_la_palette">Réception de la palette</option>
<option value="creation_mission">Création mission</option>
<option value="mission_terminee">Mission terminee</option>
<option value="modification_etat_palette">Modification etat palette</option>
</select>
</p>
<p>
<label for="pallet_status"> Statut palette :</label>
<select name="pallet_status" id="pallet_status">
<option value="ALL" selected>ALL</option>
<option value="a_stocker">A Stocker</option>
<option value="attente_ie">Attente IE</option>
<option value="probleme_dnf">Probleme DNF</option>
<option value="probleme_logistique">Probleme Logistique</option>
<option value="retour_plateforme_logistique">Retour Plateforme Logistique</option>
<option value="stockee">Stockee</option>
</select>
</p>
<p>
<label for="rupture"> Rupture :</label>
<select name="rupture" id="rupture">
<option value="ALL" selected>ALL</option>
<option value="oui">Oui</option>
<option value="non">Non</option>
</select>
</p>
<p>
<label for="date_debut"> Date : du</label>
<input type="date" name="date_debut" id="date_debut">
<label for="date_fin"> au :</label>
<input type="date" name="date_fin" id="date_fin">
</p>
<p>
<input type="submit" value="Rechercher">
</p>
</form>
</p>
</fieldset>
</center><br>
Le code php appelé par ce formulaire est le suivant :
<?php
$starting_point = $_POST['starting_point'];
$arrival_point = $_POST['arrival_point'];
$api_pallet_code = $_POST['api_pallet_code'];
$schneider_pallet_reference = $_POST['schneider_pallet_reference'];
$format_pallet = $_POST['format_pallet'];
$process_status = $_POST['process_status'];
$pallet_status = $_POST['pallet_status'];
$rupture = $_POST['rupture'];
$date_debut = $_POST['date_debut'];
$date_fin = $_POST['date_fin'];
$heure_debut = "00:00:00";
$heure_fin = "23:59:59";
$date_debut_complete = $date_debut." ".$heure_debut;
$date_fin_complete = $date_fin." ".$heure_fin;
try
{
$bdd = new PDO('mysql:host=localhost;dbname=com_api_mirfleet_schneider;charset=utf8', 'root', '');
}
catch (Exception $e)
{
die('Erreur : '.$e->getMessage());
}
$req = "SELECT * FROM reporting_missions_completed WHERE 1=1";
if (isset($_POST['starting_point']) && $_POST['starting_point']!='')
{
$req.=' AND starting_point=' . $_POST['starting_point'] . ' ';
}
echo $req;
$req->execute();
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css" href="style.css">
<title>Control Tower : Logistique</title>
</head>
<header>
<center><img src="images/banniere_haute_1400px.png" class="banniere_haute" alt="Image bannière haute"></center>
<br>
</header>
<body>
<h2>Resultats de la recherche :</h2><br>
<center><table id="dataTable" class="table">
<tr>
<th><p>#</p></th>
<th><p>Point de départ</p></th>
<th><p>Point d'arrivée</p></th>
<th><p>ID unique</p></th>
<th><p>Réference palette</p></th>
<th><p>Format palette</p></th>
<th><p>Status du process</p></th>
<th><p>Status de la palette</p></th>
<th><p>Rupture</p></th>
<th><p>Date & heure</p></th>
</tr>
<tr>
<?php
while ($donnees = $req->fetch())
{
?>
<td><center><?php echo $donnees['id']; ?></center></td>
<td><center><?php echo $donnees['starting_point']; ?></center></td>
<td><center><?php echo $donnees['arrival_point']; ?></center></td>
<td><center><?php echo $donnees['api_pallet_code']; ?></center></td>
<td><center><?php echo $donnees['schneider_pallet_reference']; ?></center></td>
<td><center><?php echo $donnees['format_pallet']; ?></center></td>
<td><center><?php echo $donnees['process_status']; ?></center></td>
<td><center><?php echo $donnees['pallet_status']; ?></center></td>
<td><center><?php echo $donnees['rupture']; ?></center></td>
<td><center><?php echo $donnees['status_datetime']; ?></center></td>
</tr>
<?php }
$req->closeCursor();
?>
</table></center><br>
<p>
<form action="pageLogistique.php">
<button type="submit">Page précédente</button>
</form>
</p>
<button id="btnExportToCsv" type="button" class="button">Exporter en CSV</button>
<script src="js/TableCSVExporter.js"></script>
<script>
const dataTable = document.getElementById("dataTable");
const btnExportToCsv = document.getElementById("btnExportToCsv");
btnExportToCsv.addEventListener ("click", () => {
const exporter = new TableCSVExporter (dataTable);
const csvOutput = exporter.convertToCSV();
const csvBlob = new Blob([csvOutput, { type: "text/csv" }]);
const blobUrl = URL.createObjectURL(csvBlob);
const anchorElement = document.createElement ("a");
anchorElement.href = blobUrl;
anchorElement.download = "table-export.csv";
anchorElement.click();
setTimeout(() => {
URL.revokeObjectURL(blobUrl);
}, 500);
});
</script>
</body>
<footer>
<center><img src="images/banniere_basse_1400px.png" class="banniere_basse" alt="Image bannière basse"></center>
</footer>
</html>
Je n'arrive absolument pas à construire ma requête dynamique, j'ai l'erreur suivante :
( ! ) Fatal error: Uncaught Error: Call to a member function execute() on string in C:\wamp64\www\dev\schneider_hmi_log\schneider_hmi_log_v1\rechercheBaseReporting.php on line 36
( ! ) Error: Call to a member function execute() on string in C:\wamp64\www\dev\schneider_hmi_log\schneider_hmi_log_v1\rechercheBaseReporting.php on line 36
Call Stack
# Time Memory Function Location
1 0.0014 412520 {main}( ) ...\rechercheBaseReporting.php:0
J'ai essayé à plusieurs reprises de modifier ma requête, je cherche dans un premier temps à prendre seulement le paramètre starting_point en compte mais même cela est compliqué...
Help please !!!
Merci d'avance.