lundi 30 mai 2016

Update query in PDO with checkboxes

I am pretty new to PDO, and i want to know how i can update my (in this case) products from a status to another status. (for example lent-out to available), their are some values wich have a dutch name. (it's for a dutch project) but i don't think that's the problem here. The DB.php is another file, wich works on other update querys (if i need to put it online i will).

 <?php
    session_start();
    require'class/DB.php';
    require 'class/clsDeleteCat.php';
    $db = new clsDB();
    ?>

    <form action="prodList.php" method="post">
        <select name="product">
            <option value="uitgeleend">Uitgeleend</option>
            <option value="beschikbaar">Beschikbaar</option>
        </select>
        <input type="submit" name="submit" value="Filter"/>
    </form>
    <?php
    $selected_val = $_POST['product'];  // Storing Selected Value In Variable
    $result2 = $db->getRow("SELECT * FROM products WHERE productStatus = '".$selected_val."' ");
    echo "<table>";
    echo "<th>Product naam</th><th>Tijd van uitlenen</th><th>Samenvatting product</th> <th>Product category</th><th>Product status</th><th>Selecteer</th>";
    while ($row = $result2->fetch()) {
        unset($prodName, $prodSummary);
        $prodName = $row['productName'];
        $prodLentTime = $row['lentTime'];
        $prodSummary = $row['productSummary'];
        $prodCategory = $row['productCategory'];
        $prodStatus = $row['productStatus'];
        echo "<tr><td  hidden>" . $row['productId'] . "</td>";
        echo "<tr><td>" . $prodName . "</td>";
        echo "<td>" . $prodLentTime . "</td>";
        echo "<td>" . $prodSummary . "</td>";
        echo "<td>" . $prodCategory . "</td>";
        echo "<td>" . $prodStatus . "</td>";
        ?>
        <td><input type="checkbox" name="checkbox[]" value="<?php echo $row['productId'];?>"/></td>
        <?php
    }
    ?>
    </table>
    <form method="post">
        <input type="submit" name="submit1" value="updaten">
    </form>
</div>
</body>
</html>
<?php
if(isset($_POST['submit1']))
{
    ini_set('memory_limit', '64m');
    if (isset($_POST['checkbox']))
    {
        $check = rtrim(implode($_POST['checkbox'], ','));
        // Alle aangevinkte rijen worden verwijderd
        $updateRows = $db->updateRow("UPDATE products SET productStatus = 'available' WHERE productId IN ($check)");


        // If rows get updated refresh the page
        if ($updateRows == TRUE)
        {
            header("Refresh:0");

        } // If something went wrong
        else
        {
           echo "Something failed";
        }
    }
}

?>




Aucun commentaire:

Enregistrer un commentaire