Learn what a CRM is and why businesses use it to remember customers.
A spreadsheet can store customer names, and a PHP page reading a JSON file can also store customer names. What actually makes the second one a CRM and the first one just a list?
A spreadsheet stores data; it doesn't decide what to show you next or connect that data to an actual program acting on it. The PHP page reads the same kind of data, but it's wired into a real, running system — a browser request triggers it, it can grow to add tasks, notes, and follow-ups around each contact, and it can change behavior based on what the data actually says. The data is the same shape either way; the difference is that one of them is part of a working system and one is just a file someone opens by hand.
CRM stands for Customer Relationship Management. Stripped of the business language, it means one specific thing: a system that remembers people, what's happened with them, and what should happen next — instead of relying on memory, scattered notes, or a spreadsheet nobody keeps updated.
This course builds the simplest version of that idea that's still real: an actual PHP file, on an actual server, reading and writing an actual JSON file. Nothing here is a toy or a simulation — it's the same three pieces — browser, server, JSON — covered separately in earlier courses, now working together for one real purpose.
The browser's job, covered in an earlier course, is to send a request and display whatever comes back. The server's job is to do the actual work — here, that means PHP reading a JSON file, deciding what to show, and sending HTML back. Nothing about that division changes just because the data happens to be customer contacts.
JSON, covered in its own course, is simply the format this CRM's data lives in — an array of contact objects, each with a name, an email, and a few other fields, exactly the shape earlier JSON lessons already covered in depth.
This lesson builds the entire foundation the rest of this course stands on: one PHP file, one JSON file, and a page that reads the contacts and displays them — deliberately small, so every later lecture only has to add one new capability to something that already works.
The whole CRM, stage one: read contacts, display them
$contactsFile = __DIR__ . '/contacts.json'; — Points at a JSON file living right next to this PHP file.
__DIR__
is PHP's way of saying "wherever this script actually is," so the path works no matter where the whole project gets moved.
$json = file_get_contents($contactsFile); — Reads the entire file into one string. At this point it's still just text — the exact same raw JSON text covered in earlier JSON lessons, not yet usable as real data.
$contacts = json_decode($json, true); — Turns that text into a real PHP array, the same parsing step
JSON.parse()
performs in JavaScript — the
true
argument specifically asks for a plain array instead of a different PHP object type.
<?php foreach ($contacts as $contact) { ?> — PHP and HTML sit directly side by side here — this loop runs once per contact, and everything between its opening and closing braces is real HTML, repeated once for each one.
<?php echo $contact['name']; ?> — Reads one specific field off the current contact and prints it directly into the HTML — the exact same dot-or-bracket access pattern covered for reading nested JSON data in an earlier course, just written in PHP's array syntax instead.
A working system beats a perfect spreadsheet nobody updates
A beautifully organized spreadsheet that three different people stopped updating six months ago provides less real value than this small, plain PHP page that's actually wired into something — being part of a real system matters more than how polished the data storage looks.
Three already-known pieces, combined, are what make this real
Nothing in this lecture's code is new — file reading, JSON parsing, and a PHP loop printing HTML were all covered separately before. What's new is seeing them work together toward one actual purpose, which is the entire shift from "knowing the pieces" to "building something."
A missing JSON file fails differently than a missing spreadsheet
If
contacts.json
doesn't exist at the expected path,
file_get_contents()
returns
false
instead of throwing a clear, obvious error — and
json_decode(false, true)
quietly returns
null, which the
foreach
loop below would then fail on, in a way that doesn't immediately point back at the actual missing file.
Mixing PHP and HTML directly is a deliberate, common pattern, not a shortcut
Switching in and out of
<?php ?> tags throughout a page, rather than building the whole HTML string separately first, is a standard way to generate dynamic pages in PHP — it reads almost like a template with the loop logic embedded directly where it's needed.
This same shape will hold for every other lecture in this course
Read JSON, loop over it, print HTML — every later lecture in this series adds exactly one new capability on top of this same three-step shape, rather than replacing it with something different each time.
Paste your PHP file into ChatGPT and ask: "Does this use an absolute path for the JSON file, and what would actually happen if contacts.json didn't exist or contained invalid JSON?" It's good at tracing that failure path, though actually renaming the file temporarily and reloading the page is the fastest way to see the real error yourself.
Create
contacts.json
with an array of three contact objects, each with a
name
and an
email.
Build the PHP page from this lesson and confirm all three contacts display correctly in the browser.
Add a fourth contact directly to the JSON file by hand, reload the page, and confirm it appears without changing any PHP code.
Temporarily rename
contacts.json
to something else and reload the page. Observe the actual error PHP produces.
Break the JSON syntax on purpose — remove a closing brace — and observe what
json_decode()
actually returns instead of throwing a clear error.
Using a relative file path instead of
__DIR__, which works while testing locally and then breaks the moment the project is deployed somewhere with a different working directory.
Assuming
file_get_contents()
or
json_decode()
will throw a clear error on failure, rather than checking what they actually return when something goes wrong.
Treating this small PHP-and-JSON page as a toy exercise rather than recognizing it as a real, complete, working system — small doesn't mean fake.
Editing the JSON file with invalid syntax by hand and being confused when the page breaks, without checking the file's actual validity first.
Forgetting that everything inside the
foreach
loop's braces is real, live HTML, and accidentally breaking the loop by mismatching a brace somewhere inside it.
Read a JSON file from PHP, loop over its contents, and display real data in HTML — combining three already-known skills into one small, genuinely working CRM foundation.