What are the best practices for inserting images into cells of a MySQL table displayed using PHP?

When inserting images into cells of a MySQL table displayed using PHP, it is best practice to store the image file path in the database rather than the actual image data. This helps in keeping the database size manageable and improves performance. To display the image, you can use the stored file path to retrieve the image and display it on the webpage.

// Inserting image file path into MySQL table
$imagePath = 'images/image.jpg'; // Path to the image file
$sql = "INSERT INTO images_table (image_path) VALUES ('$imagePath')";
$result = mysqli_query($conn, $sql);

// Displaying the image in PHP
$sql = "SELECT image_path FROM images_table WHERE id = 1";
$result = mysqli_query($conn, $sql);
$row = mysqli_fetch_assoc($result);
$imagePath = $row['image_path'];
echo "<img src='$imagePath' alt='Image'>";