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 6915097
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:25:54+00:00 2026-05-27T09:25:54+00:00

How can I show my all blog post with images? Example: Mysql table: post_id

  • 0

How can I show my all “blog post” with images? Example:
Mysql table:

post_id | user_id | subject | message | image | img_name.

What is the php code to display all my posts with images in the index page? I used the following code but it doesn’t display images, it shows only data. I would like to see something like this:

image | message is here
image | message is here
image | message is here

I used 3 pages

  1. add_post.php(Html form)
  2. add_post_process.php(process the add_post.php)
  3. index.php (which shows my all post)

add_post_process.php:

<?php
include "db.php";
@$file = addslashes($_FILES['image']['tmp_name']);
$lastid= mysql_insert_id();
@$img = addslashes(file_get_contents($_FILES['image']['tmp_name']));
$img_name = addslashes($_FILES['image']['name']);
@$img_size = getimagesize($_FILES['image']['tmp_name']);
$upload_path = './blogpostimg/';
$post_id = addslashes($_POST['post_id']);
$user_id = addslashes($_POST['user_id']);
$subject = addslashes($_POST['subject']);
$message = addslashes($_POST['message']);
$cat_id = addslashes($_POST['cat_id']);
$cat_name = addslashes($_POST['cat_name']);
$comment_count = addslashes($_POST['comment_count']);
$ch_img = addslashes($_FILES['image']['name']);
$query = "SELECT img_name FROM blog_post WHERE img_name = '$ch_img';";
$result = mysql_query($query) or die (mysql_error());
if(isset($subject, $message))
{
  $errors = array();
  if(empty($subject) && empty($message) && empty($file))
  {
    $errors[] ='all field required';
  }
  else
  {
    if(empty($subject))
      $errors[] = 'Subejct requried';
    if (empty($message))
      $errors[] = 'message required';
    if(empty($file))
      $errors[] ="SORRY, you have to be upload a image";
    elseif($img_size == FALSE)
    {
      $errors[] ="That's not an image";
    }
    else
    {
      if(mysql_num_rows($result) != 0)
      $errors[] = " You have to change this image name, already exit in our database";
    }
  }
  if(!empty($errors))
  {
    foreach($errors as $error)
    {
      echo "<ul>";
      echo "<strong><font color=red><li>$error</li></font></strong><br/>";
      echo "</ul>";
    }
  }
  else
  {
    if(!move_uploaded_file($_FILES['image']['tmp_name'],$upload_path . $img_name))
    {
      die('File Not Uploading');
    }
    else
    {
      $lastid = mysql_insert_id();
      $query = mysql_query("INSERT INTO blog_post VALUES ('', '',   '$subject',
        '$img','$img_name','$message','$cat_id','$cat_name','',NOW() )");
      if($query)
        echo "Successfully uploaeded your post";
      else
      {
        echo "Something is wrong to Upload";
      }
    }
  }
}
?>

index.php

<?php
include "db/db.php";
$upload_path = "/secure/content/blogpostimg";
$sql= mysql_query("SELECT * FROM blog_post");
while ($rel = mysql_fetch_assoc($sql))
{
  $id = $rel['post_id'];
  $sub = $rel['subject'];
  $imgname = $rel['img_name'];
  $img = $rel ['image'];
  $msg = $rel['message'];
  $date = $rel['date'];
  echo "<h1>". "$sub" ."</h1>". "<br/>";
  echo "$imgname" ."<br/>";
  echo '<img src="$upload_path " />';
  echo "$msg" . "<br/>";
  echo "$date" . "<br/>";
  echo "<hr/>";
  echo "<br/>";
}
?>

The mysql table structure is

post_id(int)
User_id(int)
subject(varchar)
image(blob)
img_name(varchar)
message(text)
  • 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-27T09:25:55+00:00Added an answer on May 27, 2026 at 9:25 am

    change

    echo '<img src="$upload_path " />';
    

    to

    echo '<img src="' . $upload_path . '/' . $img . '" />';
    

    that should do the trick..

    I don’t now if it matters in performanceways.. but howcome you use blob instead of a varchar.. 255 characters for a filename should be enough.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

if so can show simple example, ex in jquery ajax.post
can anyone recommend a website crawler that can show me all of the links
Hey all, let's jump straight to a code sample to show how ECMAScript/JavaScript/AS3 can't
In Prototype I can show a loading... image with this code: var myAjax =
I am looking for a control which can show me selected image detail view
Trying to get this example working from http://www.munna.shatkotha.com/blog/post/2008/10/26/Light-box-effect-with-WPF.aspx However, I can't seem to get
On my home page where all my blog posts are I want to show
The best example to explain my situation is to use a blog post. Let's
With this code I can show an animated gif while the server script is
We need a user control that can show Microsoft Office files (Word, Excel..). There

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.