Closed Thread
Page 12 of 22 FirstFirst ... 21011121314 ... LastLast
Results 111 to 120 of 214

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

  1. #111
    Join Date
    Nov 2009
    Posts
    20
    Rep Power
    0

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

    well written thanks

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Posts
    Many

     
  3. #112
    helena is offline Newbie
    Join Date
    Dec 2009
    Posts
    3
    Rep Power
    0

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

    HI, I tried this script in my webpage the upload works fine but i couldnt display the image it says "please select the image" when i check my mysql it shows 1 row affected..
    could u please help me resolve this problem

  4. #113
    Jaan Guest

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

    Did you edit that script?
    If yes please post it here.. then I can help you

  5. #114
    helena is offline Newbie
    Join Date
    Dec 2009
    Posts
    3
    Rep Power
    0

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

    Quote Originally Posted by Jaan View Post
    Did you edit that script?
    If yes please post it here.. then I can help you
    HI , thanks for your reply..
    if you could sorld out this issue today , it ll be very helpful to me..
    insert.php
    Code:
    <?php
    // Create MySQL login values and 
    // set them to your login information.
    $username "user1";
    $password "password1";
    $host "mysql2.ten4onehost.com";
    $database "michaels";

    // Make the connect to MySQL or die
    // and display an error.
    $link mysql_connect($host$username$password);
    if (!
    $link) {
        die(
    'Could not connect: ' mysql_error());
    }

    // Select your database
    mysql_select_db ($database); 

    // Make sure the user actually 
    // selected and uploaded a file
    if (isset($_FILES['image']) && $_FILES['image']['size'] > 0) { 

          
    // Temporary file name stored on the server
          
    $tmpName  $_FILES['image']['tmp_name'];  
           
          
    // Read the file 
          
    $fp   fopen($tmpName'r');
          
    $data fread($fpfilesize($tmpName));
          
    $data addslashes($data);
          
    fclose($fp);
          

          
    // Create the query and insert
          // into our database.
          
    $query "INSERT INTO tbl_images ";
          
    $query .= "(image) VALUES ('$data')";
          
    $results mysql_query($query$link);
          
          
    // Print results
          
    print "Thank you, your file has been uploaded.";
          
    }else{
       print 
    "No image selected/uploaded";
    }

    // Close our MySQL Link
    mysql_close($link);
    ?>
    show.php
    Code:
    <?php

    $username 
    "user1";
    $password "password1";
    $host "mysql2.ten4onehost.com";
    $database "michaels";
    @
    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'];
    $query mysql_query("SELECT * FROM tbl_images WHERE id=1);
    $row = mysql_fetch_array($query);
    $content = $row['image'];

    header('Content-type: image/jpg');
    echo $content;
    ?>
    thank you
    Last edited by Jaan; 12-15-2009 at 09:52 AM. Reason: Please use code tags when you are posting your codes!

  6. #115
    Jaan Guest

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

    Change this:
    Code:
    $query mysql_query("SELECT * FROM tbl_images WHERE id=1); 
    to this:

    Code:
    $query mysql_query("SELECT * FROM tbl_images WHERE id='1'"); 

  7. #116
    k1net1cs is offline Newbie
    Join Date
    Oct 2009
    Posts
    20
    Rep Power
    0

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

    I think this line in show.php needs to be changed :

    Code:
    $row mysql_fetch_array($query); 
    into

    Code:
    $row mysql_fetch_assoc($query); 

  8. #117
    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

    Quote Originally Posted by k1net1cs View Post
    I think this line in show.php needs to be changed :

    Code:
    $row mysql_fetch_array($query); 
    into

    Code:
    $row mysql_fetch_assoc($query); 
    Not really. mysql_fetch_array() gives back the combined answer that mysql_fetch_assoc() and mysql_fetch_row() would give, so either one is fine.
    __________________________________________
    I study Information Systems at Karlstad University when I'm not on CodeCall

  9. #118
    phb50530's Avatar
    phb50530 is offline Newbie
    Join Date
    Dec 2006
    Posts
    25
    Rep Power
    0

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

    Works perfect, thank you!

  10. #119
    k1net1cs is offline Newbie
    Join Date
    Oct 2009
    Posts
    20
    Rep Power
    0

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

    Quote Originally Posted by Orjan View Post
    Not really. mysql_fetch_array() gives back the combined answer that mysql_fetch_assoc() and mysql_fetch_row() would give, so either one is fine.
    Ah, right, my bad. =/
    Playing MW2 after quite a few hours straight with code analyzing don't really mix well...

    Anyway, I can't see where in the codes that could make it says "please select the image" anywhere...?

  11. #120
    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

    I'd say that your line shall be:

    Code:
    $query mysql_query("SELECT * FROM tbl_images WHERE id='$id'"); 
    and the line above, is even better if it is:
    Code:
    $id mysql_real_escape_string($_GET['id']); 
    __________________________________________
    I study Information Systems at Karlstad University when I'm not on CodeCall

Closed Thread
Page 12 of 22 FirstFirst ... 21011121314 ... LastLast

Thread Information

Users Browsing this Thread

There are currently 2 users browsing this thread. (0 members and 2 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