Skip to content

LinkisLethe/BNBU_SecondhandStore

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Second-Hand Store Management System

PHP SQLite PDO

中文

Background

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.

Core features

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

Portable edition improvements

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

Tech stack

  • PHP 8.1 or later
  • PDO with SQLite
  • Server-rendered HTML and CSS
  • Session authentication and CSRF tokens
  • Transactional inventory and cash updates

Quick start

Initialize the database. The script creates admin@example.test by default and prints a randomly generated administrator password once.

php scripts/init_db.php

You can provide a different administrator email and password:

php scripts/init_db.php admin@example.test your-strong-password

Start the local server:

php -S 127.0.0.1:8000 -t public

Open http://127.0.0.1:8000. Registered users can buy from or sell to the store. Administrators can manage inventory and inspect recent transactions.

Test

php tests/integration.php

The integration test creates an isolated temporary database and checks registration, login, purchases, sales, stock changes, cash changes, and transaction recording.

Project structure

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

Data and limitations

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.

About

A PHP and SQLite second-hand store with authentication, transactional inventory updates, and cash tracking.

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages