Je voudrais faire un logiciel de caisse.
J'ai deux pages index.php et ajax.
la page index.php me permet de créer plusieurs lignes(En fait ce sont des ajouts de produit dans une boutique pour un client qui
veut acheter plusieurs produits)
cette page fait ressortir tous les produits et on sélectionne le produit qu'un client désire.
la page ajax.php fait sortir les données qui sont liées à la base de données quand on sélectionne un produit sans recharger la page.
Mais il y a un problème.Quand on choisit le produit sur la première ligne, les données liées à ce produit s'affichent .
Mais à partir de la deuxième ligne, quand on choisit un autre produit, les données ne s'affichent pas.
voici index.php
Le problème se trouve en mon sens dans le code javascript.Or je ne suis pas du tout bon en javascript.Votre aide s'il vous plaît.
Code : Tout sélectionner
<?php
session_start();
?>
<!DOCTYPE html>
<html><head>
<meta charset="UTF-8">
<!--<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />-->
<title>Groupe Scolaire Avicenne</title>
<body >
<?php
if (function_exists('mb_ereg_replace'))
{
function mb_escape(string $string)
{
return mb_ereg_replace('[\x00\x0A\x0D\x1A\x22\x25\x27\x5C\x5F]', '\\\0', $string);
}
} else {
function mb_escape(string $string)
{
return preg_replace('~[\x00\x0A\x0D\x1A\x22\x25\x27\x5C\x5F]~u', '\\\$0', $string);
}
}
?>
<h2 id="fichecnedt"></h2>
<?php
?>
<h3>
</h3>
<?php
if (isset ($_POST ['nombre']))
{
$nombre=$_POST['nombre'];
}
?>
<table style="text-align: left; width: 100%;" border="0"
cellpadding="2" cellspacing="2">
<tbody>
<tr>
<td valign="top">
<?php
//include("entete.php");
?>
</td>
<td valign="top">
<div>
<table >
<tbody>
<tr>
<td>
</h3>
<h3>
<form name="test" method="post" action="achat6.php">
<input type="number" step="0" min="1" max="10" name="nombre" size="5" value="" class="note">-
<button type="submit" class="btn btn-primary">Choisir le nombre de notes</button>
</form>
</td>
</tr>
</tbody>
</table>
<div style="text-align: center;">
<?php
// include("recupere.php");
?></div>
</div><div id="fichecnedt"> </div>
</pre>
</form>
<?php if (!isset($_POST['nombre']))
{
$nombre=1;
}?>
<form name="test" method="post" action="enfin.php" onsubmit="return hiplahupbarlbatluc();">
<?php
//création d'un formulaire fictif
for($i=0;$i<$nombre;$i++){
?>
<table style="text-align: center; width: 100%;" border="5"
cellpadding="2" cellspacing="2">
<tbody>
<tr>
<td><form action="entree.php" method="POST">
<?php
require_once('configu.php');
$qry = "SELECT * FROM lesentrees order by nompr asc ";
$rs = $dbConn->query($qry);
$fetchAllData = $rs->fetch_all(MYSQLI_ASSOC);
?>
<div>
<label></label>
<select name="id" id="customer-list">
<option value="0"> ----</option>
<?php
foreach($fetchAllData as $customerData)
{
$customerID = $customerData['idpr'];
//$createFullName = $customerData['nompr']." ".$customerData['last_name'];
echo '<option value = "'.$customerID.'">'.$customerData['nompr'].'</option>';
}
?>
</select>
</div>
<img src="img/ajax-loader.gif" id="loader">
<div id="customer-data"></div>
<script src="jquery.minv.js"></script>
<script>
$(document).ready(function(){
$("#customer-list").change(function(){
$("#loader").show();
var getUserID = $(this).val();
if(getUserID != '0')
{
$.ajax({
type: 'GET',
url: 'ajax.php',
data: {customer_id:getUserID},
success: function(data){
$("#loader").hide();
$("#customer-data").html(data);
}
});
}
else
{
$("#customer-data").html('');
$("#loader").hide();
}
});
});
</script>
<br><br>
<input type=text list=browsers4582 name="matricule" autocomplete="off" PLACEHOLDER="Matricule de l'acheteur">
<datalist id=browsers4582 >
<?php
include("configu.php");
$sql18 = "SELECT DISTINCT matriculelog,nomlog FROM logscolarite order by nomlog asc ";
foreach ($bdd->query($sql18) as $data) {
// on affiche les informations de l'enregistrement en cours
// echo '<option >'.$data['pseudo'].'</option>';
echo ' <option value="'.$data['matriculelog'].'">'.$data['nomlog'].'
';
}
?>
</datalist>
<input type=text list=browsersfoi name="nom" autocomplete="off" PLACEHOLDER="Nom de l'acheteur">
<datalist id=browsersfoi >
<?php
include("configu.php");
$sql18 = "SELECT DISTINCT matriculelog,nomlog,prenomlog FROM logscolarite order by nomlog asc ";
foreach ($bdd->query($sql18) as $data) {
// on affiche les informations de l'enregistrement en cours
// echo '<option >'.$data['pseudo'].'</option>';
echo ' <option value="'.$data['nomlog'].' '.$data['prenomlog'].'">
'.$data['matriculelog'].'
';
}
?>
</datalist>
<input type=text list=browsersvvv required aria-required="true" name="zone" autocomplete="off" PLACEHOLDER="Zone">
<datalist id=browsersvvv >
<?php
include("configu.php");
$sql18 = "SELECT DISTINCT nomzone,lieuzone FROM zone order by nomzone asc ";
foreach ($bdd->query($sql18) as $data) {
// on affiche les informations de l'enregistrement en cours
// echo '<option >'.$data['pseudo'].'</option>';
echo ' <option ">'.$data['nomzone'].'
';
}
?>
</datalist>
<br><br>
<br><br>
</td> </tr>
</tbody> <?php
}// fin foreach
?>
</table>
<center>
<!-- <input type="submit" name="valider" value="VALIDER NOTE" >-->
<div id ="tumasvutumvoisplus">
<input type="submit" name="valider" value="VALIDER" >
<!--<input id="submit" type="image" src="image/save.jfif" style="width:70px;height:70px;"style="width:500px;height:600px;" value="submit" onclick="this.src='past.png';"/>--></center>
</form>
<br>
</td>
<td valign="top">
<?php
///include("entete2.php");
?> </td>
</tr>
</tbody>
</table>
</body>
</html>
voici ajax.php
Code : Tout sélectionner
<?php
require_once('configu.php');
if(isset($_GET['customer_id']) && is_numeric($_GET['customer_id']))
{
$userID = $_GET['customer_id'];
$qry = "select * from lesentrees where idpr = ".$userID;
$rs = $dbConn->query($qry);
$fetchAllData = $rs->fetch_ALL(MYSQLI_ASSOC);
$createTable = '<table>';
$createTable .= '<tr>';
$createTable .= '<th>Nom</th>';
$createTable .= '<th>ID du produit</th>';
$createTable .= '<th>Prix</th>';
$createTable .= '<th>Qté</th>';
$createTable .= '<th>Info</th>';
$createTable .= '</tr>';
foreach($fetchAllData as $customerData)
{
$createTable .= '<tr>';
$createTable .= '<td>'.$customerData['nompr'].'
<input type="text" name="produit" value="'.$customerData['nompr'].'" />
</td>';
$createTable .= '<td>'.$customerData['matriculepr'].'
<input type="hidden" name="matprod" value="'.$customerData['matriculepr'].'" />
</td>';
$createTable .= '<td>'.$customerData['prixpr'].'
<input type="number" name="montant" value="'.$customerData['prixpr'].'" />
</td>';
$createTable .= '<td>
<input type="number" required aria-required="true" name="nbre" PLACEHOLDER="Qté" />
</td>';
$createTable .= '<td>'.$customerData['infopr'].'
<textarea id="textarea" name="comm" rows="4" cols="15" placeholder="Si vous avez une autre description , c\'est ici..." ></textarea>
</td>';
$createTable .= '</tr>';
}
$createTable .= '</table>';
echo $createTable;
$rs->close();
$dbConn->close();
}
?>