模态页面ID未知

时间:2018-10-14 13:42:21

标签: javascript php

晚上好!我的模式页面和PHP页面的ID出现问题。确实,我的php页面ID在我的JS文件(AJAX)中可以正常工作,但是在同一PHP页面中包含的我的模式页面之一却无法正常工作。当我尝试使用模式页面中包含的ID时,结果在我的PHP页面的字段中显示为数组的子形式,它们在此字段中为“未定义:未定义....”。这是我的页面及其源代码的图像。

img1

img2

页面PHP:

<?php require_once $_SERVER['DOCUMENT_ROOT'].'/Vente en Ligne/coeur/initialiser.php';
      include'pages/entete.php'; 
      include'pages/navigation.php';
      $sql="SELECT * FROM produits WHERE supprimer=0";
      $presultat=$db->query($sql);

    if (isset($_GET['ajouter'])) {
      	$marqueQuery=$db->query("SELECT * FROM marque ORDER BY marque");
      	  

    function chargement()
    {
      if (isset($_GET['ajouter'])) {
        $db = mysqli_connect('127.0.0.1','root','','venteenligne');

      	$parentQuery=$db->query("SELECT * FROM categories WHERE parent=0 ORDER BY categorie");
      	while ($parent=mysqli_fetch_array($parentQuery))
      	{
      		$afficher.='<option value="'.$parent["id"].'">'.$parent["categorie"].'</option>';
      	}
      	return $afficher;
      }
    }

      ?>
  
    <h2 class="text-center">Ajouter a un nouveau Produit</h2><hr>
    <form class="produits.php?ajouter=1" method="POST" enctype="multipart/form-data">
    <div class="form-group col-md-3">
      <label for="title">Titre*:</label>
      <input type="text" class="form-control" name="titre" id="titre" value="<?php echo ((isset($_POST['titre']))? $_POST['titre']:'') ;?>">
     </div>
      <div class="form-group col-md-3">
      	<label for="marque">Marque*:</label>
      	<select class="form-control" id="marque" name="marque">
      	  <option value=""> <?php echo((isset($_POST['marque']) && $_POST['marque']=='')?'':'');?></option>
      	   <?php while ($marque=mysqli_fetch_assoc($marqueQuery)):?>

                 <option value="<?php echo $marque['id'];?>"<?php echo((isset($_POST['marque']) && $_POST['marque']==$marque['id'])?'selected':'');?>><?php echo $marque['marque'];?></option>
           <?php endwhile;?>
      	</select>
     	
      </div>
      <div class="form-group col-md-3">
      	<label>Catégorie Parent*:</label>
      	<select  class="form-control" id="part" name="part">
      	  <option value=""></option>
      	  <?php echo chargement();?>
        </select>
      </div>

      <div class="form-group col-md-3">
      	<label for="enfant">Catégorie Enfant*:</label>
      	<select class="form-control" id="enfant" name="enfant">
      		<option value=""></option>
      	</select>
      </div>

      <div class="form-group col-md-3">
      	<label for="prix">Prix Normal*:</label>
      	<input type="text" id="prix" name="prix" class="form-control" value="<?php echo ((isset($_POST['prix']))? $_POST['prix']:'') ;?>">
      </div>


      <div class="form-group col-md-3">
      	<label for="prix_promo">Prix Réduit*:</label>
      	<input type="text" id="prix_promo" name="prix_promo" class="form-control" value="<?php echo ((isset($_POST['prix_promo']))? $_POST['prix_promo']:'') ;?>">
      </div>

      <div class="form-group col-md-3">
      	<label>Quantité & Taille*:</label>
      	<button type="button" class="btn btn-default form-control" data-target="#tailleModal" onclick="jQuery('#tailleModal').modal('toggle');return false;">Quantité & Taille</button>
      </div>
       <!-- Modal -->
        <div class="modal fade" id="tailleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
         <div class="modal-dialog modal-lg">
           <div class="modal-content">
             <div class="modal-header">
                <h5 class="modal-title" id="exampleModalLabel">Quantité & Taille</h5>
                 <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                      <span aria-hidden="true">&times;</span>
                   </button>
                     </div>
                      <div class="modal-body">
                        <div class="container-fluid">
                        <?php for($i=1; $i<=12; $i++): ?>
                           <div class="form-group col-md-4">
                             <label for="taille<?php echo $i ;?>">Taille:</label>
                             <input type="text" name="taille<?php echo $i ;?>" id="taille<?php echo $i ;?>" class="form-control">
                            </div>
                            <div class="form-group col-md-2">
                             <label for="quantite<?php echo $i ;?>">Quantité:</label>
                             <input type="number" name="quantite<?php echo $i ;?>" id="quantite<?php echo $i ;?>"  value="" min="0" class="form-control">
                            </div>
                        <?php endfor; ?> 
                        </div>
                      </div>
                    <div class="modal-footer">
                  <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                <button type="button" class="btn btn-primary" onclick="updatetaille();jQuery('#tailleModal').modal('toggle');return false;">Enregistrer Modification</button>
              </div>
           </div>
         </div>
        </div>
      <div class="form-group col-md-3">
      	<label for="tailles">Quantité & Taille précédent:</label>
      	<input type="text" class="form-control" name="tailles" id="tailles" value="<?php echo ((isset($_POST['tailles']))? $_POST['tailles']:'') ;?>" readonly>
      </div>
      
      <div class="form-group col-md-6">
      	<label for="photo">Photo du Produit*:</label>
      	<input type="file" class="form-control" name="image" id="image">
      </div>
      
      <div class="form-group col-md-6">
      	<label for="description">Description*:</label>
      	<textarea id="description" name="description" class="form-control" rows="6"><?php echo ((isset($_POST['description']))?$_POST['description']:'');?></textarea>
      </div>
      
      <div class="form-group pull-right col-md-4">
      	<input type="submit" value="Ajouter Produit" class="form-control btn btn-success pull-right">
      </div><div class="clearfix"></div>
       

     </form>

     <?php }else{
      if (isset($_GET['envedette'])) {
      	$id=(int)$_GET['id'];
      	$envedette=(int)$_GET['envedette'];
      	$envedettesql="UPDATE produits SET envedette='$envedette' WHERE id='$id'";
      	$db->query($envedettesql);
      	header('Location:produits.php');
      }
?>


<h2 class="text-center">Produits</h2>
<a href="produits.php?ajouter=1" class="btn btn-success pull-right" id="ajouter_btn">Ajouter Produit</a><div class="clearfix"></div><br>
<table class="table table-bordered table-condensed table-striped" id="table">
<thead><th></th><th>Produit</th><th>Prix</th><th>Catégorie</th><th>En Vedette</th><th>Solde</th></thead><tbody>
<?php while($produit=mysqli_fetch_assoc($presultat)): 

	$enfantid=$produit['categories'];
	$catsql="SELECT * FROM categories WHERE id='$enfantid'";
	$resultat=$db->query($catsql);
    $enfant=mysqli_fetch_assoc($resultat);
   
    $parentid=$enfant['parent'];
    $psql="SELECT * FROM categories WHERE id='$parentid'";
    $presult=$db->query($psql);
    $parent1=mysqli_fetch_assoc($presult);
    
    $categorie=$parent1['categorie'].'~'.$enfant['categorie'];
?>
<tr>
	<td>
	  <a href="produits.php?edit=<?php echo $produit;?>" class="btn btn-xls btn-default"><span class="glyphicon glyphicon-pencil"></span></a>
	  <a href="produits.php?delete=<?php echo $produit;?>" class="btn btn-xls btn-default"><span class="glyphicon glyphicon-remove"></span></a>	
	</td>
	<td><?php echo $produit['titre'];?></td>
	<td><?php echo monnaie($produit['prix']);?></td>
	<td><?php echo $categorie ;?></td>
	<td><a href="produits.php?envedette=<?php echo (($produit['envedette']==0)?'1':'0');?>&id=<?php echo $produit['id'];?>" class="btn btn-xs btn-default glyphicon glyphicon-<?php echo (($produit['envedette']==1)?'minus':'plus');?>"<span class="glyphicon glyphicon-<?php echo (($produit['envedette']==1)?'minus':'plus');?>"></span></a>&nbsp <?php echo (($produit['envedette']==1)?'produit en vedette':'');?></td>
	<td></td>
</tr>
<?php endwhile; ?>
</tbody>
</table>

<?php } include'pages/pieddepage.php'; ?>

和我用ajax编写的代码:

function updatetaille(){
    var i,taillecaract='';
    var taille=jQuery('#taille'+i).val();
    var quantite=jQuery('#quantite'+i).val();
    for(var i=1;i<=12;i++){
        if (taille!='') {
          taillecaract+=taille+':'+quantite+',';
        }
      }
      jQuery("#tailles").val(taillecaract);
    }

    $(document).ready(function(){ 

		$('#part').change(function(){
         var parent=$(this).val();
          $.ajax({
          	url:"/Vente en Ligne/admin/parsers/enfantcategories.php",
          	method:"POST",
          	data:{parentid:parent},
          	dataType:"text",
          	success:function(data)
          	{
              $('#enfant').html(data);
          	}
          });
		});
});

感谢您的帮助。

0 个答案:

没有答案