0

When i'm trying to display the image from the database the image is not been displayed didn't know what was the problem,here is my code.

show_desc.php

<?php 
  $errmsg = "";

  if (! @mysql_connect("localhost","root","")) {
    $errmsg = "Cannot connect to database";
  }

  @mysql_select_db("dbname");

  if (isset($_GET['img_name'])) {
    $gotten = @mysql_query("select img from image where img_id = ".$_GET['img_name']);

    header("Content-type: image/x-ms-bmp");

    while ($row = mysql_fetch_array($gotten)) {
      print $row['img'];
    }
    mysql_free_result($gotten);
  }
  ?>

display.php

  <?php
    $errmsg = "";

    if (! @mysql_connect("localhost","root","")) {
      $errmsg = "Cannot connect to database";
    }

    @mysql_select_db("dbase_mgb");

    $strSQL = "select * from image";
    $rsPix = mysql_query($strSQL);
    $numRows = mysql_numrows($rsPix);

    $i = 0;

    while($i < $numRows) {
  ?>

  <image src="show_desc.php?img_id=<?php echo mysql_result($rsPix,$i,"img_id"); ?>"

  <?php

    $i++;

    }
  ?>

can anyone please help me with this?

OMG Ponies
  • 325,700
  • 82
  • 523
  • 502
Shruti
  • 741
  • 4
  • 14
  • 25

3 Answers3

1
  1. Your display.php doesn't seem to produce proper <img> tags.
  2. Check that your img field in the database is marked as BINARY
Mewp
  • 4,715
  • 1
  • 21
  • 24
  • this forum is not allowing me to put the image tag, it is immediately after the while condition ,image is not displayed even if the img field in the database is marked as BINARY – Shruti Jun 26 '10 at 13:55
1

i thing you use image data type as BLOB

Bhanu Prakash Pandey
  • 3,805
  • 1
  • 24
  • 16
0

Why are you strong images into the database? It is better idea to simply save the name/path of the images into the database, upload them to a folder and show them while retrieving their name in <img> tags.

Sarfraz
  • 377,238
  • 77
  • 533
  • 578
  • Which means they wouldn't be captured in a mysqldump, and has a huge risk of disconnection/lack of referential integrity – OMG Ponies Jun 26 '10 at 13:53
  • @Shruti: See this thread plz: http://stackoverflow.com/questions/450876/upload-image-to-server-using-php-store-file-name-in-a-mysql-database-with-other – Sarfraz Jun 26 '10 at 14:01