tags:

views:

53

answers:

3

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?

+1  A: 
  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
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
A: 

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
Which means they wouldn't be captured in a mysqldump, and has a huge risk of disconnection/lack of referential integrity
OMG Ponies
@sAC can you please tell me how to do that...thank you
Shruti
@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
+1  A: 

i thing you use image data type as BLOB

Bhanu