" . htmlspecialchars($error_msg) . "
"; echo "Check debug.log for more details.
"; echo "" . htmlspecialchars(implode("\n", $debug)) . ""; exit(); } $debug[] = "Connected successfully to database: $dbname"; // Check if table exists $table_check = $conn->query("SHOW TABLES LIKE 'code_for_sale'"); if ($table_check === false) { $error_msg = "Table check failed: " . $conn->error; $debug[] = $error_msg; error_log($error_msg); echo "
" . htmlspecialchars($error_msg) . "
"; echo "" . htmlspecialchars(implode("\n", $debug)) . ""; $conn->close(); exit(); } if ($table_check->num_rows == 0) { $error_msg = "Table 'code_for_sale' does not exist in database '$dbname'"; $debug[] = $error_msg; error_log($error_msg); echo "
" . htmlspecialchars($error_msg) . "
"; echo "Please create the table using the provided SQL:
"; echo "CREATE TABLE IF NOT EXISTS code_for_sale ( id INT AUTO_INCREMENT PRIMARY KEY, code_name VARCHAR(100) NOT NULL, code_description TEXT NOT NULL, code_link VARCHAR(255) NOT NULL );"; echo "
" . htmlspecialchars(implode("\n", $debug)) . ""; $conn->close(); exit(); } $debug[] = "Table 'code_for_sale' exists"; // Check table structure $structure_check = $conn->query("SHOW COLUMNS FROM code_for_sale"); if ($structure_check === false) { $error_msg = "Structure check failed: " . $conn->error; $debug[] = $error_msg; error_log($error_msg); echo "
" . htmlspecialchars($error_msg) . "
"; echo "" . htmlspecialchars(implode("\n", $debug)) . ""; $conn->close(); exit(); } $required_columns = ['code_name', 'code_description', 'code_link']; $existing_columns = []; while ($column = $structure_check->fetch_assoc()) { $existing_columns[] = $column['Field']; } $missing_columns = array_diff($required_columns, $existing_columns); if (!empty($missing_columns)) { $error_msg = "Missing required columns in 'code_for_sale': " . implode(", ", $missing_columns); $debug[] = $error_msg; error_log($error_msg); echo "
" . htmlspecialchars($error_msg) . "
"; echo "Ensure table has columns: id (INT, PRIMARY KEY), code_name (VARCHAR), code_description (TEXT), code_link (VARCHAR).
"; echo "" . htmlspecialchars(implode("\n", $debug)) . ""; $conn->close(); exit(); } $debug[] = "Table structure verified: All required columns present"; // Query to fetch code data $sql = "SELECT code_name, code_description, code_link FROM code_for_sale"; $debug[] = "Executing query: $sql"; $result = $conn->query($sql); if ($result === false) { $error_msg = "Query failed: " . $conn->error; $debug[] = $error_msg; error_log($error_msg); echo "
" . htmlspecialchars($error_msg) . "
"; echo "" . htmlspecialchars(implode("\n", $debug)) . ""; $conn->close(); exit(); } $debug[] = "Query executed successfully, found " . $result->num_rows . " rows"; if ($result->num_rows > 0) { echo "
Code Name | Code Description | Link to Code |
---|---|---|
" . htmlspecialchars($row["code_name"]) . " | "; echo "" . htmlspecialchars($row["code_description"]) . " | "; echo "View Code | "; echo "
No code available for sale. Please insert data into the table.
"; echo "INSERT INTO code_for_sale (code_name, code_description, code_link) VALUES ('Quantum Script', 'A futuristic JavaScript library for animations.', 'https://example.com/quantum-script'), ('Neon API', 'API for Tron-style UI components.', 'https://example.com/neon-api');"; } // Output debug info echo "
" . htmlspecialchars(implode("\n", $debug)) . ""; // Close connection $conn->close(); $debug[] = "Database connection closed"; error_log(implode("\n", $debug)); ?>