+ Reply to Thread
Page 4 of 16
FirstFirst ... 2 3 4 5 6 14 ... LastLast
Results 31 to 40 of 158

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

  1. #31
    Xav
    Xav is offline
    Code Slinger Xav has much to be proud of Xav has much to be proud of Xav has much to be proud of Xav has much to be proud of Xav has much to be proud of Xav has much to be proud of Xav has much to be proud of Xav has much to be proud of Xav has much to be proud of Xav's Avatar
    Join Date
    Mar 2008
    Location
    The North Pole
    Posts
    13,210
    Blog Entries
    13

    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. #32
    Newbie sanyal is an unknown quantity at this point
    Join Date
    Dec 2008
    Posts
    5

    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 09:39 AM. Reason: Please use code tags when you're posting your codes!

  3. #33
    Administrator Jordan is a name known to all Jordan is a name known to all Jordan is a name known to all Jordan is a name known to all Jordan is a name known to all Jordan is a name known to all Jordan's Avatar
    Join Date
    Nov 2005
    Location
    Hendersonville, NC
    Posts
    24,556
    Blog Entries
    97

    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?

  4. #34
    Newbie sanyal is an unknown quantity at this point
    Join Date
    Dec 2008
    Posts
    5

    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 09:51 AM. Reason: Please use code tags when you're posting your codes!

  5. #35
    Moderator Orjan is a glorious beacon of light Orjan is a glorious beacon of light Orjan is a glorious beacon of light Orjan is a glorious beacon of light Orjan is a glorious beacon of light Orjan's Avatar
    Join Date
    Sep 2007
    Location
    Karlstad, Sweden
    Age
    34
    Posts
    2,613
    Blog Entries
    7

    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

  6. #36
    Moderator Jaan is a splendid one to behold Jaan is a splendid one to behold Jaan is a splendid one to behold Jaan is a splendid one to behold Jaan is a splendid one to behold Jaan is a splendid one to behold Jaan is a splendid one to behold Jaan's Avatar
    Join Date
    Dec 2006
    Location
    Estonia
    Age
    18
    Posts
    2,066
    Blog Entries
    9

    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!
    Trill Hosting - Cheap SSL, Cheap Web Hosting, Register Cheap Domains, Cheap Blog Hosting
    www.trillhosting.com | support@trillhosting.com
    Hosting Plans | Write To Us | Support | Client Area | About Us

    CodeCall Blog | CodeCall Wiki

  7. #37
    Newbie sanyal is an unknown quantity at this point
    Join Date
    Dec 2008
    Posts
    5

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

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

  8. #38
    Moderator Jaan is a splendid one to behold Jaan is a splendid one to behold Jaan is a splendid one to behold Jaan is a splendid one to behold Jaan is a splendid one to behold Jaan is a splendid one to behold Jaan is a splendid one to behold Jaan's Avatar
    Join Date
    Dec 2006
    Location
    Estonia
    Age
    18
    Posts
    2,066
    Blog Entries
    9

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

    Does it works now?
    and no problem
    Trill Hosting - Cheap SSL, Cheap Web Hosting, Register Cheap Domains, Cheap Blog Hosting
    www.trillhosting.com | support@trillhosting.com
    Hosting Plans | Write To Us | Support | Client Area | About Us

    CodeCall Blog | CodeCall Wiki

  9. #39
    Newbie sanyal is an unknown quantity at this point
    Join Date
    Dec 2008
    Posts
    5

    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 07:51 AM. Reason: Please use code tags when you're posting your codes!

  10. #40
    Moderator Orjan is a glorious beacon of light Orjan is a glorious beacon of light Orjan is a glorious beacon of light Orjan is a glorious beacon of light Orjan is a glorious beacon of light Orjan's Avatar
    Join Date
    Sep 2007
    Location
    Karlstad, Sweden
    Age
    34
    Posts
    2,613
    Blog Entries
    7

    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

+ Reply to Thread
Page 4 of 16
FirstFirst ... 2 3 4 5 6 14 ... LastLast

Thread Information

Users Browsing this Thread

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

     

Similar Threads

  1. Tutorial: Storing Images in MySQL with PHP
    By Jordan in forum PHP Tutorials
    Replies: 43
    Last Post: 01-16-2010, 10:35 AM
  2. Tutorial: PHP to MySQL
    By Jordan in forum PHP Tutorials
    Replies: 20
    Last Post: 08-28-2009, 04:22 AM

Bookmarks

Bookmarks

     
        Algorithms and Data Structures

        Java tutorials

        Algorithms Forum

Posting Permissions

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