A store that buys and resells used items must keep customer accounts, inventory, purchase and sale prices, stock levels, and cash changes consistent. This web application supports those workflows through customer and administrator interfaces.
The first implementation used mysqli with a MySQL-compatible database. The current edition uses PDO and SQLite so the complete application can run locally without an external database server.
- Register and authenticate customer accounts.
- Browse available inventory and purchase items from the store.
- Sell items to the store and update stock and cash balances together.
- Create, update, and delete inventory through administrator-only actions.
- Record purchases and sales in a transaction ledger.
- Initialize a reproducible local database with clearly marked demo data.
- Replaced SQL string construction with prepared statements.
- Added password hashing, session-based authentication, role checks, and CSRF protection.
- Read prices from the database instead of trusting hidden form fields.
- Wrapped inventory and cash updates in database transactions.
- Corrected the buyer and seller price direction: customers buy at the store's sale price and sell at its purchase price.
- Added a transaction ledger, reproducible schema, demo seed data, and an integration test.
- PHP 8.1 or later
- PDO with SQLite
- Server-rendered HTML and CSS
- Session authentication and CSRF tokens
- Transactional inventory and cash updates
Initialize the database. The script creates admin@example.test by default and prints a randomly generated administrator password once.
php scripts/init_db.phpYou can provide a different administrator email and password:
php scripts/init_db.php admin@example.test your-strong-passwordStart the local server:
php -S 127.0.0.1:8000 -t publicOpen http://127.0.0.1:8000. Registered users can buy from or sell to the store. Administrators can manage inventory and inspect recent transactions.
php tests/integration.phpThe integration test creates an isolated temporary database and checks registration, login, purchases, sales, stock changes, cash changes, and transaction recording.
public/ Web entry points and static assets
src/ Database, authentication, store service, and view helpers
database/ SQLite schema and clearly marked demo seed data
scripts/ Database initialization command
storage/ Ignored runtime database files
tests/ Isolated integration test
The earlier database export was not available, so database/seed.sql contains new demo inventory values for local reproduction and does not claim to restore previous records. The application is intended for local demonstration: it has no payment gateway, delivery workflow, or production deployment configuration.