A simple PHP sample application to demonstrate user registration and listing using plain PHP + MySQL.
This project contains a registration form, a users listing page, and a small demo database schema and data. It's intentionally lightweight and built for learning, experimentation, and as a starting point for more robust applications.
- User registration form (HTML form)
- Server-side input validation and sanitization
- Password hashing with PHP
password_hash() - Prepared statements using mysqli to prevent SQL injection
- Simple success/error notices driven by PHP session messages and a tiny JS helper
- Simple user listing with basic styling
- SQL schema and sample data included
- Windows (development environment shown here; works the same on macOS/Linux)
- XAMPP (Apache, MySQL) or an equivalent PHP + MySQL setup
- PHP 8.x or higher (project uses
password_hash()and other built-ins) - Optional: phpMyAdmin or MySQL client to import SQL
- Copy the repository folder into the
htdocsdirectory of XAMPP. For example:
# If you cloned here already to c:\xampp\htdocs, nothing to do. Otherwise, copy files into htdocs.
# Example (PowerShell):
Copy-Item -Path "C:\path\to\sample_php_forms\*" -Destination "C:\xampp\htdocs\phpforms\" -Recurse-
Start Apache and MySQL via the XAMPP control panel.
-
Create the database and import the provided schema and sample data.
phpMyAdmin option:
- Open
http://localhost/phpmyadminand importdatabase/phpforms.sql(choose 'Import' → select file).
Command‑line option (PowerShell):
# Create database (if it doesn't exist) and import
mysql -u root -p -e "CREATE DATABASE IF NOT EXISTS phpforms;"
mysql -u root -p phpforms < "C:\xampp\htdocs\phpforms\database\phpforms.sql"Note: The project uses a default DB configuration in config.php (root / empty password and database phpforms). If you use different credentials, update config.php.
- Configure DB credentials (if needed):
- Edit
config.phpand sethostname,username,password, anddatabaseappropriately.
Example config.php:
<?php
return [
"hostname" => "localhost",
"username" => "root",
"password" => "",
"database" => "phpforms"
];- Visit the app in your browser:
- Registration form:
http://localhost/phpforms/(opensindex.php) - Users listing:
http://localhost/phpforms/users.php
index.php- Registration form viewregister.php- Form processing, validation, and DB save logicusers.php- Simple user listingconfig.php- Database configuration (returning an array)database.php- Opens the mysqli connection usingconfig.phpsettingsfunctions.php- Helper functions (validation, redirect, debug)main.js- Small script that hides notices after a timeoutstyle.css- Minimal styling for notices and tablestemplates/notice.php- Notification block for success/error messagesdatabase/phpforms.sql- SQL dump containing schema and sample datanotes.txt- Developer notes / field mappings
This project is a simple educational example and not production-ready. Consider the following improvements before using it in production:
- Add CSRF protection to forms (tokens or same-site cookies).
- Escape all output on the page where user-derived values are displayed (e.g.,
htmlspecialchars()for table values onusers.php) to prevent XSS. - Use HTTPS in production to protect credentials and session cookies.
- Consider using PDO with explicit error handling or a DB abstraction layer to unify error handling and make prepared statements easier across drivers.
- Add server-side validation and stricter input constraints (length checks, format checks).
- Rate-limit registration endpoints to prevent abuse or spam registrations.
- Use environment variables or a more secure store for DB credentials rather than a repository file for sensitive data.
- Database connection error: Check
config.phpto ensure your DB credentials are correct and MySQL is running. 404onindex.php: Ensure the project folder exists underhtdocsand that Apache has permission to serve it.- Blank pages: Check your PHP error log (or enable display_errors for local dev).
- Add a login page and authentication (sessions + login/logout)
- Add update/delete user functionality (with confirm flows and protection)
- Add search and pagination to the users list
- Add client-side validation and better UX/feedback
Contributions and suggestions are welcome. Please open an issue if you find a bug or want to propose a feature.
This project is licensed under the MIT License — see the LICENSE file for details.