Реклама
📢

Дигитал трафик

Канал о digital-маркетинге, трафике и росте бизнеса

@trafficisobar

Ответы1

О
Олег@yarovik00
15 нояб., 02:23
config.php"; // Check connection if ($conn->connect_error) { die(json_encode(['status' => 'error', 'message' => 'Connection failed: ' . $conn->connect_error])); } // Get data from the client-side request $input = file_get_contents('php://input'); $data = json_decode($input, true); $name = $data['name']; $description = $data['description']; $sku = $data['sku']; $barcode = $data['barcode']; $price = $data['price']; $cost = $data['cost']; $stock = $data['stock']; $category = $data['category']; $manufacturer = $data['manufacturer']; $weight = $data['weight']; $length = $data['length']; $width = $data['width']; $height = $data['height']; $location = $data['location']; $supplier = $data['supplier']; $active = $data['active']; $date_created = date('Y-m-d H:i:s'); $date_updated = date('Y-m-d H:i:s'); // Prepare and bind the INSERT statement $stmt = $conn->prepare("INSERT INTO product (name, description, sku, barcode, price, cost, stock, category, manufacturer, weight, length, width, height, location, supplier, active, date_created, date_updated) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"); $stmt->bind_param("ssssssssssssssssss", $name, $description, $sku, $barcode, $price, $cost, $stock, $category, $manufacturer, $weight, $length, $width, $height, $location, $supplier, $active, $date_created, $date_updated); // Execute the statement if ($stmt->execute()) { // Get the ID of the newly inserted product $product_id = $stmt->insert_id; // Create directory for the product $baseDir = '../../../images4/'; $newDir = $baseDir . $product_id; // Create the directory with proper error handling if (!file_exists($newDir)) { if (mkdir($newDir, 0755, true)) { $response = [ 'status' => 'success', 'message' => 'New record created successfully', 'product_id' => $product_id, 'directory_created' => true ]; } else { $response = [ 'status' => 'success', 'message' => 'New record created but directory creation failed', 'product_id' => $product_id, 'directory_created' => false ]; } } else { $response = [ 'status' => 'success', 'message' => 'New record created but directory already exists', 'product_id' => $product_id, 'directory_created' => false ]; } echo json_encode($response); } else { echo json_encode(['status' => 'error', 'message' => 'Error: ' . $stmt->error]); } $stmt->close(); $conn->close(); ?> попробуй от нейронки