Hello guys, Here i am having another error.
Error is undefined index on my products.php page i tried everything i can to define it but if i define it code doesn't work
so here's the code
products.php:
And this is how i tried to define it :Code:<?php require_once $_SERVER['DOCUMENT_ROOT'].'/**/core/init.php'; //Including database path stored in init.php include 'includes/head.php'; //Including header include 'includes/navigation.php'; //Including Navigation bar $sql = "SELECT * FROM products WHERE deleted = 0"; $presults = $db->query($sql); $product = mysqli_fetch_assoc($presults); // Featured product if (isset($_GET['featured'])) { $id = (int)$_GET['id']; //this where i am getting error $featured = (int)$_GET['featured']; $featuredSql = "UPDATE `products` SET `featured` = '$featured' WHERE `products`.`id` = '$product[id]' "; $db->query($featuredSql); } ?> <h2 class="text-center">Products</h2><hr /> <table class="table table-bordered table-condensed table-striped"> <thead> <th></th> <th>Product</th> <th>Price</th> <th>Category</th> <th>Featured</th> <th>Sold</th> </thead> <tbody> <?php while($product = mysqli_fetch_assoc($presults)): ?> <tr> <td> <a href="products.php?edit=<?= $product['id']; ?>" class="btn btn-xs btn-default"><span class= " glyphicon glyphicon-pencil"></span></a> <a href="products.php?delete=<?= $product['id']; ?>" class="btn btn-xs btn-default"><span class= " glyphicon glyphicon-remove-sign"></span></a> </td> <td><?= $product['title']; ?></td> <td><?= money($product['price']) ?></td> <td></td> <td><a href="products.php?featured=<?= (($product['featured'] == 0)?'1':'0'); ?>&id =<?= $product['id']; ?>" class=" btn btn-sx btn-default"> <span class=" glyphicon glyphicon-<?= (($product['featured'] == 1)?'minus':'plus'); ?>"></span> </a>  <?= (($product['featured'] == 1)?'Featured':''); ?></td> <td></td> </tr> <?php endwhile; ?> </tbody> </table> <?php include 'includes/footer.php'; //Including footer ?>
// This is 1st try
// This is 2nd tryCode:if (isset($_GET['featured']) && isset($_GET['id'])) { $id = (int)$_GET['id']; $featured = (int)$_GET['featured']; $featuredSql = "UPDATE `products` SET `featured` = '$featured' WHERE `products`.`id` = '$product[id]' "; $db->query($featuredSql); }
In the first try error disappered but featured didn't update in databaseCode:$id = ''; if (isset($_GET['featured'])) { $id = (int)$_GET['id']; $featured = (int)$_GET['featured']; $featuredSql = "UPDATE `products` SET `featured` = '$featured' WHERE `products`.`id` = '$product[id]' "; $db->query($featuredSql); }
i also tried to echo $id and var_dump$id but that didn't show anything



Reply With Quote

Bookmarks