connect_error) { die("Connection failed: " . $conn->connect_error); } // Assuming database connection is already established // Set how many items to display per page (4 items) $itemsPerPage = 4; // Get total items for the Requirements and Available Products (same table in your case - 'sell') $totalItemsQuery = "SELECT COUNT(*) FROM sell"; // Assuming 'sell' table has both products and requirements $totalItemsResult = $conn->query($totalItemsQuery); $totalItems = $totalItemsResult->fetch_row()[0]; $totalPages = ceil($totalItems / $itemsPerPage); // Calculate total pages // Get current page from URL (defaults to 1 if not set) $currentPage = isset($_GET['page']) ? (int)$_GET['page'] : 1; if ($currentPage > $totalPages) $currentPage = $totalPages; // Ensure it doesn't exceed total pages if ($currentPage < 1) $currentPage = 1; // Ensure it doesn't go below 1 // Calculate offset for the SQL query $offset = ($currentPage - 1) * $itemsPerPage; // Fetch 4 items for Requirements (from 'sell' table) for the current page $requirementsQuery = "SELECT * FROM sell LIMIT $offset, $itemsPerPage"; $requirements = $conn->query($requirementsQuery); // Fetch 4 items for Available Products (from 'sell' table) for the current page $availableProductsQuery = "SELECT * FROM sell LIMIT $offset, $itemsPerPage"; $availableProducts = $conn->query($availableProductsQuery); // Fetch Sell Products for Slider $sql = "SELECT imagePath FROM sell"; $result = $conn->query($sql); $sliderImages = []; if ($result->num_rows > 0) { while ($row = $result->fetch_assoc()) { $sliderImages[] = $row['imagePath']; } } else { $sliderImages = []; // No images available } // Handle Buy Form Submission if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['buy'])) { $productName = $_POST['productName']; $productDesc = $_POST['productDesc']; $quantity = $_POST['quantity']; $contactNumber = $_POST['contactNumber']; $district = $_POST['district']; // Get the district value from the form $email = $_POST['email']; // Verify reCAPTCHA only if it's set if (isset($_POST['g-recaptcha-response'])) { $recaptchaSecret = '6Lck8mMqAAAAAGYGj-PtChr6ec0uLcpwcAp7rC74'; // Replace with your secret key $recaptchaResponse = $_POST['g-recaptcha-response']; // Make a POST request to verify the CAPTCHA $response = file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret={$recaptchaSecret}&response={$recaptchaResponse}"); $responseKeys = json_decode($response, true); if (intval($responseKeys["success"]) !== 1) { die("Please complete the CAPTCHA."); } else { // Continue with your form processing (insert into database, etc.) } } else { die("Please complete the CAPTCHA."); } // Insert into 'buy' table $stmt = $conn->prepare("INSERT INTO buy (productName, productDesc, quantity, contactNumber, district, email) VALUES (?, ?, ?, ?, ?, ?)"); if ($stmt === false) { die('Prepare failed: ' . $conn->error); } $stmt->bind_param("ssisss", $productName, $productDesc, $quantity, $contactNumber, $district, $email); // Bind the district parameter $stmt->execute(); $stmt->close(); // Redirect to avoid form resubmission on page refresh header("Location: " . $_SERVER['REQUEST_URI']); exit(); } // Handle Sell Form Submission if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['sell'])) { $productName = $_POST['sell-product-name']; $productDesc = $_POST['sell-product-description']; $quantity = $_POST['sell-quantity']; $district = $_POST['district']; // Get the district value from the form $imagePath = ""; // Handle image upload if (!empty($_FILES['sellImages']['name'][0])) { $targetDir = "uploads/"; $imagePath = $targetDir . basename($_FILES['sellImages']['name'][0]); move_uploaded_file($_FILES['sellImages']['tmp_name'][0], $imagePath); } // Verify reCAPTCHA only if it's set if (isset($_POST['g-recaptcha-response'])) { $recaptchaSecret = '6Lck8mMqAAAAAGYGj-PtChr6ec0uLcpwcAp7rC74'; // Replace with your secret key $recaptchaResponse = $_POST['g-recaptcha-response']; // Make a POST request to verify the CAPTCHA $response = file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret={$recaptchaSecret}&response={$recaptchaResponse}"); $responseKeys = json_decode($response, true); if (intval($responseKeys["success"]) !== 1) { die("Please complete the CAPTCHA."); } else { // Continue with your form processing (insert into database, etc.) } } else { die("Please complete the CAPTCHA."); } //Insert into 'sell' table $stmt = $conn->prepare("INSERT INTO sell (productName, productDesc, quantity, district, imagePath) VALUES (?, ?, ?, ?, ?)"); if ($stmt === false) { die('Prepare failed: ' . $conn->error); } $stmt->bind_param("ssiss", $productName, $productDesc, $quantity, $district, $imagePath); // Bind the district parameter $stmt->execute(); $stmt->close(); // Redirect to avoid form resubmission on page refresh header("Location: " . $_SERVER['REQUEST_URI']); exit(); } // Fetch products for the current page $buyProductsQuery = "SELECT * FROM buy LIMIT $offset, $itemsPerPage"; // Change table name if needed $buyProducts = $conn->query($buyProductsQuery); // Fetch Buy Products $buyProducts = $conn->query("SELECT * FROM buy"); // Fetch Sell Products $sellProducts = $conn->query("SELECT * FROM sell"); // Enable error reporting error_reporting(E_ALL); ini_set('display_errors', 1); // Close the connection when done $conn->close(); ?> Dashboard
Product Image
'; } } else { echo '

No images available

'; } ?>

Requirements

fetch_assoc()): ?>

Available Products

fetch_assoc()): ?>
Advertisement Area