prepare( 'UPDATE products SET name = ?, sku = ?, category = ?, price = ?, stock = ? WHERE id = ?' ); $stmt->execute([$name, $sku, $category, $price, $stock, $id]); // Redirect to products list on success header('Location: products.php?status=updated'); exit; } catch (PDOException $e) { // Handle DB error, e.g., log error and redirect // For development, you might want to see the error // error_log($e->getMessage()); header('Location: product_edit.php?id=' . $id . '&error=db'); exit; } } // Redirect if accessed directly header('Location: products.php'); exit;