beginTransaction(); $stmt = $db->prepare("INSERT INTO marketing_videos_v3 ( producto_id, foto_producto, estado, orden, fecha_creacion ) VALUES (?, ?, 'PENDIENTE', ?, CURRENT_TIMESTAMP)"); $stmt->execute([ $producto_id, $foto_path, $orden ]); $video_id = $db->lastInsertId(); if (!$video_id) { throw new Exception("No se pudo obtener el ID del video insertado."); } // Guardar costo inicial en la tabla de costos V3 $stmt_costo = $db->prepare("INSERT INTO marketing_costos_v3 (video_id, costo_producto, inversion_total) VALUES (?, ?, ?)"); $stmt_costo->execute([$video_id, $costo_producto, $costo_producto]); $db->commit(); $redirect = $_POST['redirect'] ?? 'calculo_costos_v3.php?success=1'; header('Location: ' . $redirect); exit(); } catch (Exception $e) { if ($db->inTransaction()) { $db->rollBack(); } error_log("Error en save_marketing_video_v3.php: " . $e->getMessage()); header('Location: calculo_costos_v3.php?error=' . urlencode($e->getMessage())); exit(); } } else { header('Location: calculo_costos_v3.php'); exit(); } ?>