Skip to content
PHP Logo

What resources or tutorials would you recommend for someone looking to create a simple guestbook with image upload using PHP?

To create a simple guestbook with image upload using PHP, you can start by setting up a form that allows users to input their name, message, and upload an image. You will also need to create a PHP script to handle the form submission, validate the input, and save the data to a database along with the uploaded image. Here is a basic example of PHP code to get you started:

php
```php
<?php
// Check if form is submitted
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    // Validate input
    $name = $_POST["name"];
    $message = $_POST["message"];
    
    // Check if image file is uploaded
    if ($_FILES["image"]["error"] == 0) {
        $image = $_FILES["image"]["tmp_name"];
        $image_name = $_FILES["image"]["name"];
        
        // Save image to uploads directory
        move_uploaded_file($image, "uploads/" . $image_name);
    } else {
        $image_name = "";
    }
    
    // Save data to database
    // Your database connection code here
    
    // Display success message
    echo "Guestbook entry submitted successfully!";
}
?>

<form method="post" enctype="multipart/form-data">
    Name: <input type="text" name="name"><br>
    Message: <textarea name="message"></textarea><br>
    Image: <input type="file" name="image"><br>
    <input type="submit" value="Submit">
</form>
```

This code snippet includes a form for users to input their name, message, and upload an image. It also includes PHP code to handle the form submission, validate the input, and save the data to a database along with the uploaded image. Remember to adjust the code according to your specific requirements and database setup.