FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Image not showing





bukaida
When this student Project, was hosted in my localhost , it was working fine.But when hosted it here, the inserted image is not coming although it is inserted in the database.There was no error message.The following is the script I used for display--

Script for insertion

Code:

<?
$filename = $_FILES['file']['tmp_name'];
   if (($handle = fopen($filename, "rb"))) {
        $stream = fread($handle, filesize($filename));
        fclose($handle);
        unlink($_FILES['file']['tmp_name']);
        $type = $_FILES['file']['type'];
       
        include 'connect.php';
       
        $qstr = sprintf("INSERT INTO `image` VALUES ('', '%s', '%s')",
            mysql_real_escape_string($type),
            mysql_real_escape_string($stream));
        mysql_query($qstr, $conn) or die(mysql_error());
    }
   // header("Location: show_image.php");
   ?>


And code to display image

Code:

<?
    include 'connect.php';
    if(isset($_POST['submit'])){
    $st_id=$_POST['id'];;}
    $qstr = "SELECT * FROM `image`,`student`
             where student.im_id=image.im_id
             and s_id='$st_id'";
    $res = mysql_query($qstr, $conn) or die(mysql_error());
    while ($row = mysql_fetch_assoc($res)) {
        echo '<img src="image.php?im_id='.$row["im_id"].' " width="150" height="150" align="right"><br>';
    }   
?>


The Structure of image table is--

Code:
im_id int(10) NOT NULL auto_increment,
  type varchar(16) NOT NULL default '',
  stream longblob NOT NULL,
  PRIMARY KEY (im_id))TYPE = INNODB";


The structure of student table is

Code:
s_id VARCHAR(10) NOT NULL UNIQUE,
   s_fname VARCHAR(20)NOT NULL,
   s_mname VARCHAR(20)NOT NULL,
   s_lname VARCHAR(20)NOT NULL,
   s_gname VARCHAR(30)NOT NULL,
    s_address VARCHAR(50)NOT NULL,
    s_dob DATE,
   s_gender VARCHAR(6)NOT NULL,
   s_class VARCHAR(3)NOT NULL,
    s_section VARCHAR(1)NOT NULL,
   s_height INT(4),
    s_weight INT(4),
   s_g_income VARCHAR(20)NOT NULL,
   s_photo VARCHAR(50)NOT NULL,
   s_marks INT(4),
    s_rank VARCHAR(5)NOT NULL,
   s_hobbies VARCHAR(50)NOT NULL,
   im_id int(10) NOT NULL auto_increment,
   PRIMARY KEY(im_id))TYPE = INNODB";


A dummy record inserted with student id s1.

Please help.
Stubru Freak
It gives these errors:
Code:
Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /home/bukaida/domains/pratik.frih.net/public_html/school/image.php on line 4

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/bukaida/domains/pratik.frih.net/public_html/school/image.php on line 5

Could you show the image.php code?
bukaida
Thank you man, The culprit was image.php.I forgot to update the connection string.After your suggestion, I updated it and now it is working.BTW how did you got that warning message? In my screen, It was not showing anything.Thank you again for pointing out the particular file.
Stubru Freak
You see the messages when you load the image in your browser's address bar. When you load the page containing the image, the browser will see it isn't a valid image and won't display it.
bukaida
Is there any way to display such warnings on the page itself? Will increasing the error level help?
Stubru Freak
bukaida wrote:
Is there any way to display such warnings on the page itself? Will increasing the error level help?


No. The errors are actually send to your pc, but the browser sees that the image is invalid (as it contains the errors instead of image code) and won't display it.
Related topics
How do i get an image constantly showing my game server?
Two Scripts that I need!
Need help with images
Brand new website!
Tattoo's: Do You Have One?
Weird IMG problem?
How do you get Curved Boarders on Tables
Interactive map in a game...
Interactive world map in a game....
Color suggestions need
Double standards
Extraterrestrial life.. how would we know..
Tutorial: Image Rollovers w/ Javascript
Image Mapping?
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.