This project demonstrates how to build a dynamic website using PHP and MySQL. It includes various functionalities such as displaying database records, ordering data, form handling, image uploads, and more.
-
Database Connection
Establish a connection to a MySQL database using PHP. -
Retrieve and Display Data
Fetch data from the database with ordering (ASC
orDESC
). -
Date Formatting and Time Difference
Display formatted dates and calculate time differences (e.g., "2 days ago"). -
Data Entry via HTML Forms
Submit data such as names, emails, and phone numbers to the database. -
Image Uploads
Handle file uploads (images) and save the file path to the database. -
Dynamic Menus
Generate navigation menus dynamically from the database. -
JOIN Queries
Demonstrate complex queries using SQLJOIN
to combine data from multiple tables. -
Row Count
Display the total number of rows in a database table. -
Reusable PHP Functions
Example of reusable functions likegetBlogID()
for modular code.
- Database:
MySQL
- Backend:
PHP
- Frontend: HTML/CSS (dynamic data rendering via PHP)
- File Uploads: Supported
-
Clone the Repository
git clone https://github.com/atikhasan392/documentation.git cd php-documentation
-
Database Setup
- Create a MySQL database (e.g.,
databesh
). - Import the provided SQL file to set up tables and sample data.
- Create a MySQL database (e.g.,
-
Configure Database Connection
Updatemysqli_connect
in the connection block:$con = mysqli_connect('localhost', 'root', '', 'databesh');
-
Run the Project
Place the project in your web server's root directory (e.g.,htdocs
for XAMPP).
Access the site in a browser at:http://localhost/<project-folder>
-
Database Connection
$con = mysqli_connect('localhost', 'root', '', 'databesh'); if (!$con) { die("Connection failed: " . mysqli_connect_error()); }
-
Fetch and Display Records
$query = "SELECT * FROM mydb ORDER BY addedOn DESC"; $result = mysqli_query($con, $query); while ($row = mysqli_fetch_assoc($result)) { echo $row['addedOn']; }
-
Insert Data via Form
if (isset($_POST['fast_name'])) { $fast_name = $_POST['fast_name']; $query = "INSERT INTO mytable (fast_name) VALUES ('$fast_name')"; mysqli_query($con, $query); }
-
Upload Images
$imgname = $_FILES['img']['name']; move_uploaded_file($_FILES['img']['tmp_name'], 'images/' . $imgname);
-
Dynamic Menu
$query = "SELECT * FROM menu ORDER BY order ASC"; $result = mysqli_query($con, $query); while ($menu = mysqli_fetch_assoc($result)) { echo '<a href="' . $menu['link'] . '">' . $menu['name'] . '</a>'; }
- PHP: Version 7.4 or higher
- MySQL: Version 5.7 or higher
- Web Server: Apache (Recommended: XAMPP/WAMP/LAMP)
-
Security Considerations:
- Use prepared statements to prevent SQL injection.
- Validate and sanitize user input for forms and file uploads.
-
Error Handling:
Add proper error-handling mechanisms to improve robustness. -
Styling:
Use CSS to enhance the frontend appearance as per project requirements.
For further questions or contributions, please reach out at [https://atikhasan.com] [[email protected]].