Skip to main content
Advanced Search
Search Terms
Content Type

Exact Matches
Tag Searches
Date Options
Updated after
Updated before
Created after
Created before

Search Results

89 total results found

Inserting Validated Form Data

PHP and MySQL PHP and MySQL Foundations

An insert should accept input, validate it, store it with a prepared statement and report a useful result. Example form <form method="post"> <label for="activity_name">Activity name</label> <input id="activity_name" name="activity_name" maxlength="100" req...

Selecting and Displaying Records

PHP and MySQL PHP and MySQL Foundations

A useful output begins with a query and ends with accessible, escaped HTML. Select only required fields $stmt = $pdo->query( "SELECT activity_id, activity_name, location, capacity FROM activities ORDER BY activity_name" ); $activities = $stmt->fe...

Filtering and Sorting Records

PHP and MySQL PHP and MySQL Foundations

Filters help users reduce a dataset to relevant records. Sorts place those records in a useful order. Filter with a prepared value $location = trim($_GET["location"] ?? ""); $stmt = $pdo->prepare( "SELECT activity_name, location, capacity FROM activit...

Updating Existing Records

PHP and MySQL PHP and MySQL Foundations

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

PHP and MySQL Login Systems

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

Working with Data Importing CSV into MySQL with PHP

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

Working with Data Importing CSV into MySQL with PHP

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

Working with Data Importing CSV into MySQL with PHP

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

Working with Data Importing CSV into MySQL with PHP

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

Working with Data Importing CSV into MySQL with PHP

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

Working with Data Importing CSV into MySQL with PHP

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

Working with Data Importing CSV into MySQL with PHP

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, "...

New Page

Working with Data Importing CSV into MySQL with PHP

Reporting CSV Import Results

Working with Data Importing CSV into MySQL with PHP

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

Working with Data Importing CSV into MySQL with PHP

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

Working with Data Importing CSV into MySQL with PHP

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

Working with Data Processing and Presenting Imported Data

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

Working with Data Processing and Presenting Imported Data

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...