Postingan lainnya
category menu(submenu) tak muncul di halaman backend
permisi mau tanya,disini saya mengikuti tutorial membuat toko online di salahsatu chanel youtube,dan saya dapat masalah di bagian penampilan category menu,jadi idenya ketika saya ingi n menambah produk saya memilih parent menu dulu baru bisa tahu category menunya,spt contoh: 1.parent : boys ,category : Shirt 2.parent : girls ,category :dresses
jadi tergantung parent yang di klick di option nya,ini gambarnya:
ini isi database categories saya :
dan ini penampakan error child_categories.php:
Notice: Undefined index: parentID in C:\xampp\htdocs\tokoonline\admin\parsers\child_categories.php on line 3 Boys Girls Men Women
dan ini 3 file script saya: 1.products.php
<h2 class="text-center">Add a New Product</h2><hr>
<div class="container-fluid">
<form action="products.php?add=1" method="post" enctype="multipart/form-data">
<div class="col-md-3 form-group">
<label for="title">Title*:</label>
<input type="text" name="title" id="title" class="form-control"value="<?=((isset($_POST['title']))?sanitize($_POST['title']):'')?>">
</div>
<div class="form-group col-md-3">
<label for="brand">Select a Brand</label>
<select class="form-control" name="brand" id="brand">
<option value="<?=((isset($_POST['brand'])&& $_POST['brand']=='')?'selected':'');?>"></option>
<?php while($brand = mysqli_fetch_assoc($brandQuery)): ?>
<option value="<?=$brand['id']?>"<?=((isset($_POST['brand'])&& $_POST['brand']== $brand['id'])?'selected':'')?>><?=$brand['brand']?></option>
<?php endwhile; ?>
</select>
</div>
<div class="form-group col-md-3">
<label for="parent">Select a Parent menu*:</label>
<select class="form-control" name="parent" id="parent">
<option value="<?=((isset($_POST['parent'])&& $_POST['parent']== '')?'selected':'')?>"></option>
<?php while($parent = mysqli_fetch_assoc($parentQuery)): ?>
<option value="<?=$parent['id']?>" <?=((isset($_POST['parent'])&& $_POST['parent']== $parent['id'])?'selected':'')?> ><?=$parent['category']?></option>
<?php endwhile;?>
</select>
</div>
<div class="form-group col-md-3">
<label for="child">select a category*:</label>
<select class="form-control" name="child" id="child">
</select>
</div>
</form>
</div>
2.file footer.php(isinya script javascriptnya)
</div><br><br>
<div class="clear"></div>
<div class="col-md-12 text-center footer3">
<p id="copy">© FadhilSanad Design <?=date('Y')?></p>
</div>
<script>
function get_child_options(){
var parentID = jQuery('#parent').val();
jQuery.ajax({
url : '/tokoonline/admin/parsers/child_categories.php',
type : 'POST',
data : {parentID : parentID},
success : function(data){
jQuery('#child').html(data);
},
error : function(){alert('Something went wrong');},
});
}
jQuery('select[name="parent"]').change(get_child_options());
</script>
3.ini file child_categories.php(tempat memunculkan option categori sesuai parent yang di pilih)
<?php
require_once $_SERVER['DOCUMENT_ROOT'].'/tokoonline/core/init.php';
$parentID = (int)$_POST['parentID'];
$childQuery = $db->query("SELECT * FROM categories WHERE parent = '$parentID' ORDER BY category");
ob_start();
?>
<option value=""></option>
<?php while($child=mysqli_fetch_assoc($childQuery)): ?>
<option value="<?=$child['id']?>"><?=$child['category']?></option>
<?php endwhile; ?>
<?php echo ob_get_clean(); ?>
1 Jawaban:
kalau menurut saya javascriptnya yg di footer gak kebaca,soalnya errornya saat javascriptnya saya hapus tetap sama yaitu:
Notice: Undefined index: parentID in C:\xampp\htdocs\tokoonline\admin\parsers\child_categories.php on line 3.
ini cuplikan videonya gan,kebetulan juga bnyk yang problemnya sama hehe:
https://www.youtube.com/watch?v=_kFU8D__a9w&list=PLFPkAJFH7I0mitTSKDaoxwfLLf-wNNnVS&index=15