Advanced Search
Search Results
108 total results found
Updating Existing Records
An update changes an existing row. The application must identify the row, validate changes and prevent unintended updates. Load the selected record $id = filter_input(INPUT_GET, "id", FILTER_VALIDATE_INT); if (!$id) { exit("Invalid activity."); } $stmt = $...
Protecting an Admin-Only Data Import Page
A role-based system must enforce permissions on the server. Hiding a link is helpful navigation, but it does not protect the page. Store trusted session values at login After verifying the password and retrieving the database user: session_regenerate_id(true);...
Understanding CSV Data
CSV means comma-separated values. Each line is a record and each position represents a field. match_id,team_name,wins,losses M001,Fictional Falcons,4,1 M002,Sample Sharks,3,2 The first row is a header. Quoted fields may contain commas, so do not process CSV wi...
Designing a MySQL Table from a CSV
Design the destination table from the meaning of the data, not merely its appearance in a spreadsheet. CSV field MySQL type Rule match_id VARCHAR(20) unique and required team_name VARCHAR(100) required wins INT zero or greater losses INT zero or greater CREATE...
Creating an Admin-Only CSV Upload Form
A CSV upload changes stored data and should be restricted to administrators. Apply session and role checks before any output. <?php session_start(); if (!isset($_SESSION["user_id"])) { header("Location: login.php"); exit; } if (($_SESSION["role"] ?? ""...
Validating an Uploaded CSV File
Validate the upload before reading its rows. $file = $_FILES["dataset"] ?? null; $errors = []; if (!$file || $file["error"] !== UPLOAD_ERR_OK) { $errors[] = "Choose a CSV file that uploaded successfully."; } if ($file && $file["size"] > 2 * 1024 * 1024) { ...
Reading CSV Rows with fgetcsv
Use PHP’s CSV parser so quoted commas and escaped values are handled correctly. $handle = fopen($file["tmp_name"], "r"); if ($handle === false) { exit("The uploaded file could not be read."); } $headers = fgetcsv($handle); $expected = ["match_id", "team_na...
Validating CSV Rows
Validate every row before storing it. if (count($row) !== 4) { $rowErrors[] = "Row $rowNumber has the wrong number of fields."; continue; } [$matchId, $teamName, $winsRaw, $lossesRaw] = array_map("trim", $row); $wins = filter_var($winsRaw, FILTER_VALID...
Inserting Imported Rows Safely
Prepare the insert once, then execute it for each valid row. $insert = $pdo->prepare( "INSERT INTO team_results (match_id, team_name, wins, losses) VALUES (:match_id, :team_name, :wins, :losses)" ); $insert->execute([ "match_id" => $matchId, "...
Reporting CSV Import Results
An administrator needs evidence of what happened, not just “upload complete”. Report useful totals Show the escaped filename, rows read, inserted, updated, skipped and rejected, plus row-specific validation messages and whether a transaction committed or rolle...
Building a Complete Admin CSV Import
A complete import combines access control, upload checks, parsing, row validation, prepared statements and a result summary. Processing sequence Start the session and require the administrator role. Accept a POST upload. Validate upload status, size and extens...
Testing an Admin CSV Import
Testing must cover permissions, validation, database effects and feedback. Test Condition Expected result Logged out Direct import URL Redirect to login Standard role Direct URL or POST 403; nothing imported Valid CSV Correct headings and rows Expected records...
Querying Data for a User Need
A query is meaningful when it answers a user question. Begin with the need, then choose fields, filters, calculations and order. Example need A participant wants to find the strongest fictional teams and inspect their performance. SELECT team_name, SUM(...
Building a Leaderboard
A leaderboard converts stored results into a ranked, understandable output. SELECT team_name, SUM(wins) AS wins, SUM(losses) AS losses, SUM(wins) * 3 AS points FROM team_results GROUP BY team_name ORDER BY points DESC, wins DESC, team_name...
Calculating Summary Statistics
Statistics reduce a dataset to information users can interpret. SELECT COUNT(*) AS result_count, COUNT(DISTINCT team_name) AS team_count, SUM(wins) AS total_wins, AVG(wins) AS average_wins, MAX(wins) AS highest_wins FROM team_results; Choose statisti...
Creating Match and Player Views
A detail view lets a user move from a summary to the record needed for a task. Receive a validated identifier $matchId = trim($_GET["match_id"] ?? ""); if ($matchId === "" || mb_strlen($matchId) > 20) { exit("Invalid match."); } $stmt = $pdo->prepare( "S...
Creating Charts from Processed SQL Data
A chart is useful only when it makes a comparison or pattern easier to understand. JavaScript is a supporting technology; the assessed reasoning lies in the data choice, processing and justified output. Prepare data in PHP $labels = array_column($rows, "team_n...
Exporting Processed Data to CSV
CSV export can support download and reuse of a filtered or processed result. It is optional when import already satisfies the data-transfer requirement, but can be valuable for a justified user need. Send download headers header("Content-Type: text/csv; charse...