public static function favorite_product($id, $product, $type = 'add') { global $db; if ($type == 'add') { if (!\user\main::check_favorite_product($id, $product['id'])) { $stmt = $db->stmt_init(); $stmt->prepare("INSERT INTO " . DB_TABLE_PREFIX . "favorite_product (user, product, start, expiration, date) VALUES (?, ?, ?, ?, NOW())"); $stmt->bind_param("iiss", $id, $product['id'], $product['start'], $product['expiration']); $execute = $stmt->execute(); $stmt->close(); if ($execute) { return true; } else { return false; } } } else { if ($type == 'remove') { $stmt = $db->stmt_init(); $stmt->prepare("DELETE FROM " . DB_TABLE_PREFIX . "favorite_product WHERE user = ? AND product = ?"); $stmt->bind_param("ii", $id, $product['id']); $execute = $stmt->execute(); $stmt->close(); if ($execute) { return true; } else { return false; } } } return false; }