$form_use[$value]->method('POST'); $form_use[$value]->add('Submit', 'submit')->value("Utiliser"); $form_use[$value]->bound($_POST); //construct a array with the product_id array_push($tbx_use_index, $value); } //Arrays for error and confirm message $error_buy = array(); $msg_confirm = array(); //Treatment for each form foreach ($tbx_use_index as $value) { //which product user wants to buy if ($form_use[$value]->is_valid($_POST)) { //add nutrionals aspect to rabbit skill use_product($value, $_SESSION['id_nabz']); $quantity = display_quantity($value, $_SESSION['id']); //Operation on quantity, delete if we you the last in cart or -1 if there is still some in if ($quantity - 1 == 0) { delete_product_incart($value); header("Location: index.php?module=nabz&action=treat&id=" . $_SESSION['id']); //Reload page } else { update_quantity($value); } $msg_confirm[] = "Action effectuée avec succès, votre lapin se sent déjà mieux."; } //end of is_valid } //end of foreach include PATH_VIEW . 'view_treat.php'; }
?> <?php //display each product as in the rabbit store foreach ($item_cat as $value) { $infos_product = infos_product($value); echo '<table id=\'table_product_profile\'><tbody><tr>'; echo '<td>'; echo '<img src=' . PATH_IMAGE_STORE . $infos_product['product_image'] . '>' . '<br \\>'; echo $infos_product['product_name'] . '<br \\>'; echo $infos_product['product_description'] . '<br \\>'; echo '</td>'; echo '<td>'; //health echo "<img id=\"img_skill\" src=\"" . PATH_IMAGE_RESSOURCE . "health.png\">"; echo ' ' . '+' . $infos_product['prdct_health_pt'] . '<br \\>'; //angry echo "<img id=\"img_skill\" src=\"" . PATH_IMAGE_RESSOURCE . "food.png\">"; echo ' ' . '+' . $infos_product['prdct_angry_pt'] . '<br \\>'; //thearth echo "<img id=\"img_skill\" src=\"" . PATH_IMAGE_RESSOURCE . "drink.png\">"; echo ' ' . '+' . $infos_product['prdct_thirst_pt'] . '<br \\>'; //portions echo "<img id=\"img_skill\" src=\"" . PATH_IMAGE_RESSOURCE . "portion.png\">"; echo ' ' . display_quantity($infos_product['product_id'], $_SESSION['id']) . ' portions disponibles' . '<br \\>'; echo $form_use[$value]; echo '</td></tr></tbody>'; echo '</table>'; } ?> </td> </table>
function delete_product_incart($id_product) { $pdo = PDO2::getInstance(); $quantity = display_quantity($id_product, $_SESSION['id']); $query = $pdo->prepare("DELETE FROM tbl_cart WHERE product_id = :id_product"); $query->bindValue(':id_product', $id_product); $query->execute(); return $query->rowCount() == 1; }