Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7031467
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:48:25+00:00 2026-05-28T00:48:25+00:00

I am making a gallery that uses a MySQL database (yeah I know it’s

  • 0

I am making a gallery that uses a MySQL database (yeah I know it’s a bad practice but it’s the requirement for the moment.) I can upload multiple images but I’m having trouble displaying all images stored inside the database. The FORM allows five images to be uploaded. Then the user must proceed to another page where all the images in database (including the ones uploaded recently) will be displayed together with the description of the images. I have code already but the one that will work on the display is not working or I think is wrong.

Here is the form code:

 <html>
 <head>
    <title> Upload image</title>

 </head>
 <body> 
 <div align="center">
    <form action="fUpload.php" method="POST" enctype="multipart/form-data">
    All forms must be filled. <br />
    File: <br />
    <input type="file" name="image[]"/> <input type="text" name="imageDescription[]" size="30" /> <br />
    <input type="file" name="image[]"/>  <input type="text" name="imageDescription[]" size="30" /> <br />
    <input type="file" name="image[]"/>  <input type="text" name="imageDescription[]" size="30" /> <br />
    <input type="file" name="image[]"/>  <input type="text" name="imageDescription[]" size="30" /> <br />
    <input type="file" name="image[]"/> <input type="text" name="imageDescription[]" size="30" /> <br />

    <input type="submit" value="Upload image" />

    </form>
</div>  
</body>
</html>

Here is the script that would upload:

 <?php 

//connect to the database//
$con = mysql_connect("localhost","root", "");
if(!$con)
{
 die('Could not connect to the database:' . mysql_error());
 echo "ERROR IN CONNECTION";
}

$sel = mysql_select_db("imagedatabase");
if(!$sel)
{
 die('Could not connect to the database:' . mysql_error());
 echo "ERROR IN CONNECTION";
}
//file properties//

$file = $_FILES['image']['tmp_name']; 

echo '<br />';

 /*if(!isset($file))
    echo "Please select your images";

else
{
 */for($count = 0; $count < count($_FILES['image']); $count++)
{
//$image = file_get_contents($_FILES['image']['tmp_name']);
    $image_desc[$count] = addslashes($_POST['imageDescription'][$count]);
    $image_name[$count] = addslashes($_FILES['image]']['name'][$count]); echo '<br \>';
    $image_size[$count] = @getimagesize($_FILES['image']['tmp_name'][$count]);
    $error[$count] = $_FILES['image']['error'][$count];

    if($image_size[$count] === FALSE  || ($image_size[$count]) == 0)
        echo "That's not an image";
    else
    {

    // Temporary file name stored on the server
     $tmpName[$count]  = $_FILES['image']['tmp_name'][$count];

  // Read the file
    $fp[$count]   = fopen($tmpName[$count], 'r');
    $data[$count] = fread($fp[$count], filesize($tmpName[$count]));
    $data[$count] = addslashes($data[$count]);
     fclose($fp[$count]);


  // Create the query and insert
  // into our database.

  $results = mysql_query("INSERT INTO images( description, image) VALUES             ('$image_desc[$count]','$data[$count]')", $con);

        if(!$results)
        echo "Problem uploding the image. Please check your database";  
    //else 
    //{
        echo "";
        //$last_id = mysql_insert_id();
        //echo "Image Uploaded. <p /> <p /><img src=display.php?    id=$last_id>";
        //header('Lcation: display2.php?id=$last_id');
        }
    //}
}


mysql_close($con);
header('Location: fGallery.php');
?>

And finally the one that should display:

<html>
<body>

</body>
<?php

//connect to the database//
mysql_connect("localhost","root", "") or die(mysql_error());
mysql_select_db("imagedatabase") or die(mysql_error());

//requesting image id

$id = addslashes($_REQUEST['id']);

$image = mysql_query("SELECT * FROM images WHERE id = $id");


while($datum = mysql_fetch_array($image, MYSQL_ASSOC))
{
        printf("Description %s $image = $image['image'];

header("Content-type: image/jpeg");

}

mysql_close();


?>

Your help is much appreciated. I need it badly to move on.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T00:48:26+00:00Added an answer on May 28, 2026 at 12:48 am

    From what i understand from your post is that uploading and storing isn’t a problem, but showing the images is. That’s probably because you’re using vars that are not set, so no results kan be found in the database. If i misunderstood let me know.

    <?php
    // No ID
    $image = mysql_query("SELECT * FROM images ORDER BY id DESC");   
    ?>
    

    Also look at what Prof83 says. Ignore my post if your script works with just one image.

    Last but not least, if you’re using different filetypes, also echo the correct MIME format in the header.

    Update
    I combined both answers.

    Edit your loop:

    <?php
    while($row = mysql_fetch_assoc($image))
    {
            echo '<img src="img.php?id='.$row["id"].'">';
    }
    ?>
    

    Create a page name img.php

    <?php
    $query = mysql_query("SELECT image FROM images WHERE id = ".$_GET['id']);
    $row = mysql_fetch_assoc($query);
    header("Content-type: image/jpeg");
    echo $row['image'];
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am making a photo gallery script that involves displaying an image in a
Does anyone know of a jquery plugin that can make a thumbnail of an
Basicly I'm making an image gallery that downloads from the web. So - when
I'm making a C# image gallery for a website (I know there's many free
Question Can I build a image database/library that has an e-commerce style checkout system
We are making an app that includes a digital gallery which display photos and
I’m making a gallery on site. And don’t know what the best solution for
I'm making a webpage that contains a picture gallery. I've written a javascript function
Making an adobe flex ui in which data that is calculated must use proprietary
Making UML sequence diagram in VS 2010RC I've observed that there is no activation

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.