85 lines
2.9 KiB
PHP
85 lines
2.9 KiB
PHP
<?php
|
|
require_once __DIR__ . '/includes/config.php';
|
|
require_once __DIR__ . '/includes/Security.php';
|
|
|
|
echo "=== اختبار نظام إدارة المنتجات ===\n\n";
|
|
|
|
try {
|
|
$conn = new mysqli(DB_SERVER, DB_USERNAME, DB_PASSWORD, DB_NAME);
|
|
|
|
if ($conn->connect_error) {
|
|
throw new Exception("فشل الاتصال: " . $conn->connect_error);
|
|
}
|
|
|
|
// إضافة منتج جديد
|
|
$stmt = $conn->prepare("INSERT INTO products (name, description, price, stock, category) VALUES (?, ?, ?, ?, ?)");
|
|
$name = "زيت اللافندر الطبيعي";
|
|
$description = "زيت لافندر طبيعي 100% للعناية بالبشرة والشعر";
|
|
$price = 149.99;
|
|
$stock = 50;
|
|
$category = "essential_oils";
|
|
|
|
$stmt->bind_param("ssdis", $name, $description, $price, $stock, $category);
|
|
|
|
if ($stmt->execute()) {
|
|
$product_id = $conn->insert_id;
|
|
echo "تم إضافة المنتج بنجاح (ID: $product_id)\n";
|
|
}
|
|
|
|
// استرجاع المنتج
|
|
$stmt = $conn->prepare("SELECT * FROM products WHERE id = ?");
|
|
$stmt->bind_param("i", $product_id);
|
|
$stmt->execute();
|
|
$result = $stmt->get_result();
|
|
$product = $result->fetch_assoc();
|
|
|
|
echo "\nبيانات المنتج:\n";
|
|
echo "الاسم: " . $product['name'] . "\n";
|
|
echo "السعر: " . $product['price'] . " جنيه\n";
|
|
echo "المخزون: " . $product['stock'] . " قطعة\n";
|
|
|
|
// تحديث المنتج
|
|
$new_price = 139.99;
|
|
$new_stock = 45;
|
|
|
|
$stmt = $conn->prepare("UPDATE products SET price = ?, stock = ? WHERE id = ?");
|
|
$stmt->bind_param("dii", $new_price, $new_stock, $product_id);
|
|
|
|
if ($stmt->execute()) {
|
|
echo "\nتم تحديث المنتج بنجاح\n";
|
|
}
|
|
|
|
// التحقق من التحديث
|
|
$stmt = $conn->prepare("SELECT price, stock FROM products WHERE id = ?");
|
|
$stmt->bind_param("i", $product_id);
|
|
$stmt->execute();
|
|
$result = $stmt->get_result();
|
|
$updated_product = $result->fetch_assoc();
|
|
|
|
echo "\nبيانات المنتج بعد التحديث:\n";
|
|
echo "السعر الجديد: " . $updated_product['price'] . " جنيه\n";
|
|
echo "المخزون الجديد: " . $updated_product['stock'] . " قطعة\n";
|
|
|
|
// حذف المنتج
|
|
$stmt = $conn->prepare("DELETE FROM products WHERE id = ?");
|
|
$stmt->bind_param("i", $product_id);
|
|
|
|
if ($stmt->execute()) {
|
|
echo "\nتم حذف المنتج بنجاح\n";
|
|
}
|
|
|
|
// التحقق من الحذف
|
|
$stmt = $conn->prepare("SELECT COUNT(*) as count FROM products WHERE id = ?");
|
|
$stmt->bind_param("i", $product_id);
|
|
$stmt->execute();
|
|
$result = $stmt->get_result();
|
|
$count = $result->fetch_assoc()['count'];
|
|
|
|
echo "التحقق من الحذف: " . ($count == 0 ? "ناجح ✓" : "فشل ✗") . "\n";
|
|
|
|
$conn->close();
|
|
|
|
} catch (Exception $e) {
|
|
echo "خطأ: " . $e->getMessage() . "\n";
|
|
}
|