query($tableCheckQuery)->num_rows > 0; if (!$tableExists) { $error = "Domain table does not exist."; } else { // Get the correct project name field for this domain $projectNameField = getProjectNameField($conn, $domainTable); // Get the columns of the domain table to determine field structure $columnsQuery = "SHOW COLUMNS FROM $domainTable"; $columnsResult = $conn->query($columnsQuery); $columns = []; while ($column = $columnsResult->fetch_assoc()) { $columns[$column['Field']] = $column; } // Process form submission if ($_SERVER['REQUEST_METHOD'] === 'POST') { // Validate form data $projectName = isset($_POST['project_name']) ? trim($_POST['project_name']) : ''; $projectType = isset($_POST['project_type']) ? trim($_POST['project_type']) : ''; $description = isset($_POST['description']) ? trim($_POST['description']) : ''; $email = isset($_POST['email']) ? trim($_POST['email']) : ''; $links = isset($_POST['links']) ? trim($_POST['links']) : ''; // Additional fields (if any) $additionalFields = []; foreach ($_POST as $key => $value) { if (strpos($key, 'additional_') === 0) { $fieldName = substr($key, 11); // Remove 'additional_' prefix $additionalFields[$fieldName] = trim($value); } } // Basic validation if (empty($projectName) || empty($projectType)) { $error = "Please provide project name and project type."; } else { // Prepare the SQL for update $updates = []; $values = []; $types = ''; // Add project name field $updates[] = "`$projectNameField` = ?"; $values[] = $projectName; $types .= 's'; // string for Project Name // Add project type field (H/S) if (isset($columns['H/S'])) { $updates[] = "`H/S` = ?"; $values[] = $projectType; $types .= 's'; // string for H/S } // Add description field if (isset($columns['Description'])) { $updates[] = "`Description` = ?"; $values[] = $description; $types .= 's'; // string for Description } // Add email field if (isset($columns['Email'])) { $updates[] = "`Email` = ?"; $values[] = $email; $types .= 's'; // string for Email } // Add links field if (isset($columns['Links'])) { $updates[] = "`Links` = ?"; $values[] = $links; $types .= 's'; // string for Links } // Add additional fields foreach ($additionalFields as $field => $value) { if (isset($columns[$field])) { $updates[] = "`$field` = ?"; $values[] = $value; $types .= 's'; // string for additional fields } } // Add project ID for WHERE clause $values[] = $projectId; $types .= 'i'; // integer for Project_ID // Prepare and execute the update query $updateQuery = "UPDATE $domainTable SET " . implode(', ', $updates) . " WHERE Project_ID = ?"; $stmt = $conn->prepare($updateQuery); if ($stmt) { // Dynamically bind parameters $bindParams = array_merge([$types], $values); $ref_params = []; foreach ($bindParams as $key => $value) { $ref_params[$key] = &$bindParams[$key]; } call_user_func_array([$stmt, 'bind_param'], $ref_params); if ($stmt->execute()) { $success = "Project updated successfully."; // Refresh project data $projectQuery = "SELECT * FROM $domainTable WHERE Project_ID = ? LIMIT 1"; $projectStmt = $conn->prepare($projectQuery); $projectStmt->bind_param('i', $projectId); $projectStmt->execute(); $projectResult = $projectStmt->get_result(); $project = $projectResult->fetch_assoc(); $projectStmt->close(); } else { $error = "Error updating project: " . $stmt->error; } $stmt->close(); } else { $error = "Error preparing query: " . $conn->error; } } } else { // Fetch project details $projectQuery = "SELECT * FROM $domainTable WHERE Project_ID = ? LIMIT 1"; $stmt = $conn->prepare($projectQuery); $stmt->bind_param('i', $projectId); $stmt->execute(); $result = $stmt->get_result(); if ($result && $result->num_rows > 0) { $project = $result->fetch_assoc(); } else { $error = "Project not found."; } $stmt->close(); } } // Get domain descriptions $domainDescriptions = getDomainDescriptions($conn); $domainDescription = isset($domainDescriptions[$domainNumber]) ? $domainDescriptions[$domainNumber] : "Domain $domainNumber"; // Include header include 'includes/header.php'; ?>
Project Details
$value): ?>
Cancel
close(); ?>