This PHP project is a simple web application that allows users to input details, upload photos, and displays user information, including photos.
- PHP development environment (e.g., XAMPP, WampServer).
- MySQL database.
- Create a "uploads" folder in the project directory to store uploaded images.
- Clone or download the project to your local machine.
- Set up your MySQL database and update the connection details in
connect.php
. - Create a folder named "uploads" in the project directory.
- Open the project in your PHP development environment.
-
Create a MySQL database named "assignment":
CREATE DATABASE assignment;
-
Create a "user" table within the database:
CREATE TABLE user ( id INT AUTO_INCREMENT PRIMARY KEY, name VARCHAR(255) NOT NULL, description TEXT, photo VARCHAR(255) );
- connect.php: Database connection details.
- index.php: User input form and photo upload.
- handleInput.php: Handles form submission, uploads photos, and inserts user details into the database.
- displayUserDetails.php: Displays user details, including photos, in a table.
Open index.php
in your browser, fill in the form with user details, select a photo, and click "Submit." The photo will be uploaded to the "uploads" folder, and user details will be stored in the database.
<!-- index.php -->
<!-- ... -->
<form action="handleInput.php" method="post" enctype="multipart/form-data">
<!-- ... -->
<!-- Input field for user's photo -->
<div class="mb-3">
<label for="photo" class="form-label">Photo</label>
<input type="file" class="form-control" id="photo" name="photo" accept="image/*">
</div>
<!-- ... -->
<button type="submit" class="btn btn-primary" name="submit">Submit</button>
</form>
<!-- ... -->
Visit displayUserDetails.php
in your browser to view a table displaying user details, including photos.
<!-- displayUserDetails.php -->
<!-- ... -->
<!-- Loop through each user record -->
while ($row = mysqli_fetch_assoc($result)) {
$id = $row["id"];
$name = $row["name"];
$description = $row["description"];
$photo = $row["photo"];
echo
'<tr>
<th scope="row">' . $id . '</th>
<td>' . $name . '</td>
<td>' . $description . '</td>
<!-- Display user photo -->
<td><img src="uploads/' . $photo . '" alt="User Photo" style="width: 75px; height: 75px;"></td>
</tr>';
}
<!-- ... -->