I am having a problem in displaying images from database.
This the code
gallery.php
Expand|Select|Wrap|Line Numbers
- <?php
- session_start();
- if(isset($_SESSION['$signin_name'])){}
- //die('ERROR:'.mysql_error());
- $host="localhost"; // Host name
- $username="root"; // Mysql username
- $password=""; // Mysql password
- $db_name="task2"; // Database name
- $tbl_name="imge"; // Table name
- //------------------------------------------- Building Connection ------------------------------------------//
- $con = mysql_connect("$host","$username","$password");
- if (!$con)
- {
- die('Could not connect: ' . mysql_error());
- }
- //------------------------------------------- Selecting Database -------------------------------------------//
- mysql_select_db("$db_name", $con) or die(mysql_error());
- //----------------------------------------- Selecting 'Filename' form 'imge' -------------------------------//
- //$get_image="SELECT Filename FROM $tbl_name ";
- //mysql_query($get_image) or die("Error:" . mysql_error());
- //$path= mysql_fetch_array($get_image);
- //echo $path;
- //$image = stripslashes($_REQUEST[imname]);
- //$rs = mysql_query("SELECT Filename FROM $tbl_name WHERE filename=\"".
- //addslashes($image).".jpeg\"");
- //$row = mysql_fetch_assoc($rs);
- //$imagebytes = $row[imgdata];
- if (IsSet($_GET['pixID'])){
- $rs = mysql_query("select Filename from imge where id= ".$_GET['pixID']);
- header("Content-type: image/JPEG");
- while ($row = mysql_fetch_array($rs)
- {
- print $row[$imagdata];
- }
- /*gotten = mysql_query("select Filename from imge");
- header("Content-type: image/JPEG");
- while ($row = mysql_fetch_array($gotten))
- {
- print $row['imgdata'];
- } */
- mysql_free_result($rs); }
- ?>
Displaying the images in this file
your_gallery.php
Expand|Select|Wrap|Line Numbers
- <html>
- <head>
- <TITLE>Your Image Gallery</TITLE>
- </head>
- <body>
- <h1>Look at this:</H1>
- <?php
- $host="localhost"; // Host name
- $username="root"; // Mysql username
- $password=""; // Mysql password
- $db_name="task2"; // Database name
- $tbl_name="imge"; // Table name
- //------------------------------------------- Building Connection ------------------------------------------//
- $con = mysql_connect("$host","$username","$password");
- if (!$con)
- {
- die('Could not connect: ' . mysql_error());
- }
- //------------------------------------------- Selecting Database -------------------------------------------//
- mysql_select_db("$db_name", $con) or die(mysql_error());
- $strSQL = "select * from imge";
- $rsPix = mysql_query($strSQL);
- $numRows = mysql_numrows($rsPix);
- $i = 0;
- while($i < $numRows){
- ?>
- <div style="width:33%: float:left">
- <img src="gallery.php?pixID=<?php echo mysql_result($rsPix,$i,"pixID"); ?>"/>
- <?php
- $i++;
- }
- ?>
- <br/><br/><a href="upload_view.html" title="Back">Back </a>
- </body>
- </html>