Hello guys i am doing a archived page and i have added option to restore all but after that every newly deleted product doesn't show up
here's the script

//php to get update data upon click of button
<?php

if (isset($_GET['all'])) {
        $allSql = "UPDATE products SET deleted = 0 WHERE deleted = 1";
        $allresult = $db->query($allSql);
        header('Location: products.php');
    }
?>
<?php

//restore button
 if($archived['deleted'] == 1){ ?>
<a href="archived.php?all" class="btn btn-success pull-left" id="restore-all-btn">Restore All</a>
 <?php 
  }else{
    echo "You have no archived products to show.";
}

?>

the products are updated but even if deleted =1 it doesn't show up on the page

Recommended Answers

All 2 Replies

first checks db if is really updated
second post code that show up page

db is really updated

<?php 
    require_once $_SERVER['DOCUMENT_ROOT'].'/Online Store/core/init.php';
    include 'includes/head.php';
    include 'includes/navigation.php';

    $sql = "SELECT * FROM products WHERE deleted = 1";
    $aresults = $db->query($sql);
    $archived = mysqli_fetch_assoc($aresults);
    if (isset($_GET['restore'])) {
        $restore_id = sanitize($_GET['restore']);
        $sql = "UPDATE products SET deleted = 0 WHERE id = '$restore_id'";
        $aresult = $db->query($sql);
        header('Location: products.php');
    }

    if (isset($_GET['all'])) {
        $allSql = "UPDATE products SET deleted = 0 WHERE deleted = 1";
        $allresult = $db->query($allSql);
        header('Location: products.php');
    }

?>

<h2 class="text-center">Archived</h2><hr />


<?php

 if($archived['deleted'] == 1){ ?>
<a href="archived.php?all" class="btn btn-success pull-left" id="restore-all-btn">Restore All</a>
 <?php 
  }else{
    echo "You have no archived products to show.";
}

?>

<table class="table table-bordered table-condensed">
    <thead>
        <th></th>
        <th>Products</th>
        <th>Price</th>
        <th>Categories</th>
    </thead>
    <tbody>
        <?php while($archived = mysqli_fetch_assoc($aresults)) : 
            $childID = $archived['categories'];
            $catSql = "SELECT * FROM categories WHERE id = '$childID'";
            $result = $db->query($catSql);
            $child = mysqli_fetch_assoc($result);
            $parentID = $child['parent'];
            $pSql = "SELECT * FROM categories WHERE id = '$parentID'";
            $presult = $db->query($pSql);
            $parent = mysqli_fetch_assoc($presult);
            $category = $parent['category'].'~'.$child['category'];
            ?>
            <tr>
        <tr>

            <td>
                <a href="archived.php?restore=<?= $archived['id']?>"><span class="glyphicon glyphicon-repeat"></span></a>
            </td>
            <td><?= $archived['title']; ?></td>
            <td><?= $archived['price']; ?></td>
            <td><?= $category; ?></td>
        </tr>
        <?php endwhile; ?>
    </tbody>
</table>




<?php include 'includes/footer.php'; ?>

this is the page few valus show but few doesn't show even if database is updated

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.