A manufacturer of PTFE (polytetrafluoroethylene) products ran its business on a custom PHP and MySQL system covering enquiries, quotations, sales orders, raw-material stock, production and dispatch. The software worked on the surface, but stock figures could not be trusted and, as our audit showed, the system had serious security gaps. We audited, fixed and tested it end to end, without a rewrite and without stopping daily operations.
Headline result: every page in the menu now works, stock is recorded correctly for both raw materials and finished goods, negative stock is blocked, and the two critical security holes are closed. All of this was verified by automated checks and real workflow tests on a copy of the client's data.
Project at a glance
| Detail | Value |
|---|---|
| Client type | PTFE products manufacturer (raw materials, production and finished goods) |
| System | Custom stock, production and sales software (ERP-style) |
| Modules | Enquiries, quotations, proforma invoices, sales orders, products, raw-material stock, material issue, production, finished-goods stock, dispatch, reports, dashboard |
| Engagement | Code audit, security fixes, stock-logic repair, testing and data repair |
| Tech stack | PHP · MySQL · Apache |
| Scale | 78 PHP files · 32 pages · 25 automated stock checks |
The challenge
The client's team relied on the system every day, but several problems had built up over time:
- Stock numbers did not add up. Raw materials and finished goods with the same item ID shared a single stock figure, and some stock rows were negative.
- Raw material disappeared twice. When material was issued to production, the stock was reduced once at issue and again when production started.
- Uploaded stock could not be dispatched. The same item was split across several rows because "no warehouse" was saved in different ways, so dispatch could not find stock that existed.
- Pages were crashing. The product screens, enquiries, proforma invoice items and a document upload failed with fatal errors.
- Feedback was lost. Success and error messages after saving never appeared, and "created by" was always blank.
- Security was weaker than anyone knew. This only became clear during the audit, described below.
The audit: what we found
We set up two identical copies of the application on a copy of the client's database, one original and one for fixes, and reviewed every module.
Critical security issues
- The login accepted any password. The password check had been disabled in the code, so anyone could sign in with any e-mail address.
- About 20 background action files had no login check. In a controlled test, without logging in, we were able to create an administrator account and read customer details.
Stock and data integrity issues
- Finished goods entered through purchase, upload, production and dispatch were saved without their item type, so the database stored them as raw material.
- Raw material was deducted twice during production.
- Stock could go below zero without any warning.
- Reports and registers mixed raw-material and finished-goods rows that shared an ID.
The solution
1. Closing the security holes
- Restored proper password verification at login.
- Added one central login check that every page and background request must pass, instead of relying on each file to remember it.
- Hardened sessions: a new session ID at login, secure cookie settings, and a complete sign-out.
- Blocked code from running inside the uploads folder and stopped database files from being downloaded.
2. One trusted stock engine
All stock movements (direct entry, finished-goods purchase and upload, material issue, production, dispatch) now go through a single shared stock library. It:
- always records whether an item is raw material or a finished good;
- stores "no warehouse or batch" consistently, so the same stock is never split across rows;
- blocks negative stock with a clear "Insufficient stock" message, and saves nothing when this happens;
- removes the double deduction, so raw material is reduced exactly once.
Reports and stock registers were updated to keep raw materials and finished goods separate.
3. Fixing crashes and everyday annoyances
- Repaired the fatal errors on product, enquiry, proforma invoice and upload screens.
- Fixed broken redirect links so success and error messages appear after every save.
- Recorded the correct user in "created by" across the quotation module.
- Corrected the dashboard, which queried a table that did not exist and ran queries whose results were never shown.
- Made login and logout redirects work on both the live server and the local test environment.
4. Repairing existing data
Fixing the code stops new errors, but years of incorrect stock records remained. We wrote a step-by-step data repair script that corrects the item type on old entries, removes the double deductions and rebuilds current stock balances from the movement history. Running it on data produced by the original version gave exactly the correct stock figures.
5. Safe handover
- Every original file was kept in a dated backup folder before changes were made.
- A change log listed every fix and the files it touched.
- We gave the client a simple tool to reset user passwords, because logins now check passwords again.
- We gave clear instructions for go-live: back up, run the repair script, remove a database admin tool from the live server, and move the database password out of the code.
Testing
| Check | Result |
|---|---|
| PHP syntax check | All 78 files pass |
| Pages loading without errors | 29 of 32, including every page in the menu (the other 3 are unused legacy pages) |
| Automated stock-logic checks | 25 of 25 pass |
| Real workflows through the screens | Direct stock entry, finished-goods purchase, material issue, issue to production and dispatch all save correctly |
| Over-issuing stock | Correctly blocked |
| Login and unauthorised requests | Wrong passwords and requests without login are rejected |
| Data repair script | Produced exactly the correct stock figures on broken data |
Results
- Accurate stock: raw materials and finished goods are tracked separately, with no double deductions and no negative balances.
- A secure system: passwords are checked, every request requires login, and sessions are hardened.
- Every menu page works, and users see clear confirmation after each action.
- Trustworthy history: existing stock data repaired with a repeatable, verified script.
- No disruption: the business kept running throughout, and every change can be traced and reversed.
Recommended next steps
The audit also identified improvements for the next phase:
- Page-level permissions. Menu permissions currently hide items but do not block direct page access.
- CSRF protection with a token on every form, and deletes via secure form submissions rather than plain links.
- Warehouse on finished-goods purchase, so purchased stock can be dispatched from the right location.
- Safe document numbering with database sequences, so two users saving at once never get the same number.
- A meaningful dashboard that reports raw materials (kg) and finished goods (pieces) separately.
Lessons for businesses running custom software
- "It works" is not the same as "it is correct". Regular audits find problems that daily use hides.
- Put critical rules in one place. A single stock engine and a single login check are far easier to keep right than logic copied across dozens of files.
- Fix the data, not just the code. A repair script with a backup and a clear procedure restores trust in reports.
- Test on a copy, compare against the original. Running the same steps on both versions proves exactly what changed.
Is your business software holding you back?
We audit, repair and modernise existing PHP, MySQL and web applications, without starting from scratch. Talk to our team about a code and security review.



