Closed Thread
Page 4 of 22 FirstFirst ... 2345614 ... LastLast
Results 31 to 40 of 214

Thread: Tutorial: Storing Images in MySQL with PHP / Part II / Display your images

  1. #31
    Join Date
    Mar 2008
    Location
    The North Pole
    Posts
    13,174
    Blog Entries
    13
    Rep Power
    114

    Re: Tutorial: Storing Images in MySQL with PHP / Part II / Display your images

    The ? indicates the GET arguments. Then you have name/value pairs, joined with the = symbol and separated from other pairs via the & symbol.

    Quote Originally Posted by Jordan View Post
    Good members, like yourself, stick around and post for ages to come!
    Mr. Xav | Blog | Forums

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Location
    Advertising world
    Posts
    Many

     
  3. #32
    sanyal is offline Newbie
    Join Date
    Dec 2008
    Posts
    5
    Rep Power
    0

    Re: Tutorial: Storing Images in MySQL with PHP / Part II / Display your images

    hi.......
    i am new to php...i like u r tutorial....its simple easy going....
    i tried u r example of Tutorial: Storing Images in MySQL with PHP / Part II / Display your images , but i am getting this error....somthing like this


    Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\task\show_img.php:9) in C:\xampp\htdocs\task\show_img.php on line 30

    and here is my code

    Code:
    <?php

    $username 
    "root";
    $password "";
    $host "localhost";
    $database "test";

    @
    mysql_connect($host$username$password) or die("Can not connect to database: ".mysql_error());

    @
    mysql_select_db($database) or die("Can not select the database: ".mysql_error());

    //$id = $_GET['id'];
    $id=2;
    if(!isset(
    $id) || empty($id)){
    die(
    "Please select your image!");
    }else{

    $query mysql_query("SELECT * FROM images WHERE id='".$id."'");
    $row mysql_fetch_array($query);
    $content $row['img'];

    header('Content-type: image/jpg');    =====error =====> ( line 30)
    echo 
    $content;

    }

    ?>
    thanks in advance.....waiting for the response..!
    Last edited by Jaan; 12-16-2008 at 07:39 AM. Reason: Please use code tags when you're posting your codes!

  4. #33
    Jordan Guest

    Re: Tutorial: Storing Images in MySQL with PHP / Part II / Display your images

    This error means you have already sent your headers somewhere. Do you have a space before or above <?php ? Is another script being executed first?

  5. #34
    sanyal is offline Newbie
    Join Date
    Dec 2008
    Posts
    5
    Rep Power
    0

    Re: Tutorial: Storing Images in MySQL with PHP / Part II / Display your images

    first of all thanks for u r .responce.........

    this is the whole code..........
    Code:
    <html>
    <head>
    <title>Untitled Document</title>
    <!-- <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> -->
    </head>
    
    <body>
    <?php
    
    $username = "root";
    $password = "";
    $host = "localhost";
    $database = "test";
    
    @mysql_connect($host, $username, $password) or die("Can not connect to database: ".mysql_error());
    
    @mysql_select_db($database) or die("Can not select the database: ".mysql_error());
    
    //$id = $_GET['id'];
    $id=4;
    if(!isset($id) || empty($id)){
    die("Please select your image!");
    }else{
    
    $query = mysql_query("SELECT * FROM images WHERE id='".$id."'");
    $row = mysql_fetch_array($query);
    $content = $row['img'];
    
    header('Content-type: image/jpg');
    echo $content;
    
    }
    
    ?> 
    </body>
    </html>
    .........i have commented that line as u said it might have already declared ..........
    now i am not getting the error.....but the out put...is somthing like this........

    �JFIF�������C� $.' ",#(7),01444'9=82<.342�C 2!!22222222222222222222222222222222222222222222222 222�4"������������ ����}�!1AQa"q2‘#BR$3br‚ ........and so ...on
    can u plzss...tell me what would b the problem.........and y is it happening so....!
    thanks in advance.......
    Last edited by Jaan; 12-17-2008 at 07:51 AM. Reason: Please use code tags when you're posting your codes!

  6. #35
    Join Date
    Sep 2007
    Location
    Karlstad, Sweden
    Posts
    3,082
    Blog Entries
    7
    Rep Power
    42

    Re: Tutorial: Storing Images in MySQL with PHP / Part II / Display your images

    As mentioned one page back in this thread, ABSOLUTELY NOTHING can be put before the "<?php" tag or after the "?>" for this script! It shall NOT have any HTML or HEAD or BODY, as it is NOT an Webpage, this is an image file you want to show.

    Tutorial: Storing Images in MySQL with PHP / Part II / Display your images

  7. #36
    Jaan Guest

    Re: Tutorial: Storing Images in MySQL with PHP / Part II / Display your images

    you're right orjan.. You MUST NOT have anything after and before PHP tags!

  8. #37
    sanyal is offline Newbie
    Join Date
    Dec 2008
    Posts
    5
    Rep Power
    0

    Re: Tutorial: Storing Images in MySQL with PHP / Part II / Display your images

    thanks a lot to both of u jaan and orjan.............!

  9. #38
    Jaan Guest

    Re: Tutorial: Storing Images in MySQL with PHP / Part II / Display your images

    Does it works now?
    and no problem

  10. #39
    sanyal is offline Newbie
    Join Date
    Dec 2008
    Posts
    5
    Rep Power
    0

    Re: Tutorial: Storing Images in MySQL with PHP / Part II / Display your images

    hi.........
    jaan........

    yess its working fine........ when i am trying to displaying only one image...........but when i am trying to display all the images of the tables
    then i am getting only one image that is .... the first image of the table

    here is the code

    Code:
    <?php
    
    $username = "root";
    $password = "";
    $host = "localhost";
    $database = "test";
    
    @mysql_connect($host, $username, $password) or die("Can not connect to database: ".mysql_error());
    
    @mysql_select_db($database) or die("Can not select the database: ".mysql_error());
    
    $query = mysql_query("SELECT * FROM images")or die("Cannot exe----- select the database: ".mysql_error());
    while($row = mysql_fetch_array($query)){
    //echo $row['id'];
    $content = $row['img'];
    
    header('Content-type: image/jpg');
    echo $content;
    }
    
    ?>
    and if i am trying to display other data from the table by using echo....
    say as........
    echo $row['id'];---------->it is showing error

    Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\sun\show1.php:23) in C:\xampp\htdocs\sun\show1.php on line 28
    JFIFC $.' ",#(7),01444'9=82<.342C 2!!22222222222222222222222222222222222222222222222 2224"

    and can you help me in display both images and other data from MSQL using PHP script.
    thanks in advance..............
    Last edited by Jaan; 12-20-2008 at 05:51 AM. Reason: Please use code tags when you're posting your codes!

  11. #40
    Join Date
    Sep 2007
    Location
    Karlstad, Sweden
    Posts
    3,082
    Blog Entries
    7
    Rep Power
    42

    Re: Tutorial: Storing Images in MySQL with PHP / Part II / Display your images

    No. This script is made to fetch one picture at a time.
    that's why we use the id in the url.

    if you want to show several pictures, you would need to do this in ANOTHER script:

    similar to this:
    Code:
    $query mysql_query("SELECT * FROM images")or die("Cannot exe----- select the database: ".mysql_error());
    while(
    $row mysql_fetch_array($query)){
        
    $id $row[id];
        echo 
    "<img src='fetch.php?id=$id'>";
        echo 
    $row[comment];

    This script first adds a img-tag to the html, then prints an to the picture attached comment from the database and outputs that one too.

    the filename fetch.php is just something I made up now, and is the file where the picture fetching script is in.
    Conclusion, the script fetches ordered picture. if you want to fetch several pictures, you need to order each picture to be shown from your html or another phpscript

Closed Thread
Page 4 of 22 FirstFirst ... 2345614 ... LastLast

Thread Information

Users Browsing this Thread

There are currently 3 users browsing this thread. (0 members and 3 guests)

Similar Threads

  1. Replies: 3
    Last Post: 02-07-2011, 11:29 AM
  2. Tutorial: Storing Images in MySQL with PHP
    By Jordan in forum PHP Tutorials
    Replies: 47
    Last Post: 01-04-2011, 08:37 PM
  3. Beginner Storing images in XML file - Part II - Displaying image
    By Jaan in forum PHP Tutorials
    Replies: 6
    Last Post: 01-04-2011, 08:35 PM
  4. display images sequentially using PHP and MySQL
    By jhanjon in forum PHP Development
    Replies: 2
    Last Post: 10-08-2009, 12:11 PM
  5. Replies: 2
    Last Post: 07-16-2009, 12:48 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts