Closed Thread
Page 14 of 22 FirstFirst ... 41213141516 ... LastLast
Results 131 to 140 of 214

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

  1. #131
    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

    Could you show us the code for displaying the image too?
    And I assume that funcReadWriteConn() function is your custom function to connect to the database?

    In any case, this line of the code :

    Code:
    $query="SELECT rtype FROM pixtable WHERE ucase(trim(rstaffid))='".strtoupper(trim($the_staf fid))."'"
    ...you misplaced a space in the $the_staffid variable in strtoupper(trim($the_staf fid)).


    Btw, if you're copy-pasting the code, please put 'em between the [PHP] tags, thanks...

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Posts
    Many

     
  3. #132
    scumbogs is offline Newbie
    Join Date
    Jan 2010
    Posts
    5
    Rep Power
    0

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

    Notice: Undefined index: image_id in C:\wamp\www\Untitled-9.php on line 20
    Please select your image!

    it says error on my id why is it sir?

  4. #133
    scumbogs is offline Newbie
    Join Date
    Jan 2010
    Posts
    5
    Rep Power
    0

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

    sir help me cant view my upload image thi this my upload.php

    Code:
    <body>
    <?php 
     
    // Create MySQL login values and 
    // set them to your login information.
    $username "dots";
    $password "dots";
    $host "localhost";
    $database "doctrack";

    // 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 testblob ";
          
    $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);

    ?>
    </body>
    </html>
    and my show.php

    Code:
    <body>
    <?php

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

    @
    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());

    $image_id $_GET['image_id'];

    if(!isset(
    $id) || empty($id)){
    die(
    "Please select your image!");
    }else{

    $query mysql_query("SELECT * FROM testblob WHERE image_id='".$image_id."'");
    $row mysql_fetch_array($query);
    $content $row['image'];

    header('Content-type: image/jpg');
    echo 
    $content;

    }

    ?> 
    </body>
    </html>
    THANKS so MUch
    Last edited by Jaan; 01-19-2010 at 03:51 PM. Reason: Removed database info and added tags!

  5. #134
    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

    First of all, your conditional is using the wrong variable.

    Code:
    $image_id $_GET['image_id'];

    if(!isset(
    $id) || empty($id)) {
      die(
    "Please select your image!");

    It should be :

    Code:
    $image_id $_GET['image_id'];

    if(!isset(
    $image_id) || empty($image_id)) {
      die(
    "Please select your image!");

    And then, you have to pay attention to the data type of the image_id field (or column) on your database.
    If it's a string, you can use the current code on your show.php to show it.

    If it's an integer, it should be changed from

    Code:
    $query mysql_query("SELECT * FROM testblob WHERE image_id='".$image_id."'"); 
    to

    Code:
    $query mysql_query("SELECT * FROM testblob WHERE image_id=$image_id"); 
    You also need to remove the <html> and <body> tags from your show.php.

  6. #135
    tayolad is offline Newbie
    Join Date
    Oct 2009
    Posts
    25
    Rep Power
    0

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

    Code:
    $query="SELECT staff_id,type,size,pix FROM picturetable WHERE ";
       
    $query.=" ucase(trim(staff_id))='".strtoupper(trim($the_staff_id))."'";
       
    $rst=mysql_query($query,$dbcon);
       if(
    $rst$row_no=mysql_num_rows($rst);
       if(
    $row_no>0)
       {
        
    $row=mysql_fetch_assoc($rst); 
        
    header("Content-type: image/jpeg");
        print 
    $row['pix'];
        } 
    Last edited by Jaan; 01-19-2010 at 03:52 PM. Reason: Please use code tags when you are posting your codes!

  7. #136
    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

    Thanks, Jaan...that helps a lot. =)


    @tayolad
    Hmm...yeah, I think I can see where it might get wrong, but this is just a wild guess.

    Do you use Windows as your server's OS?
    If that's the case, you should change this line :

    Code:
    $fp fopen($tmpName'r'); 
    into

    Code:
    $fp fopen($tmpName'rb'); 
    For Windows-based systems, a 'b' should be added when using fopen() to open a binary file.

    I'm also a bit confused by this line :

    Code:
    $query.=" ucase(trim(staff_id))='".strtoupper(trim($the_staff_id))."'"
    Why didn't you just write it like this?

    Code:
    $query.="staff_id='".strtoupper(trim($the_staff_id))."'"

  8. #137
    Jaan Guest

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

    @Kinetics.. and you are right again those functions wont work if they are written like they were before.

  9. #138
    hardinera's Avatar
    hardinera is offline Learning Programmer
    Join Date
    Jul 2009
    Posts
    42
    Rep Power
    0

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

    why does when i call show.php inside the table it only displays the URL and not the image?

    when i call show.php alone its working fine but when i include it with some php it doest work at all. and it eds up not displaying anything at all except the URL of the page -.- i dont have any idea why its not working lol -.-

    my code is something like this

    Code:
    <table width="800" border="0">
      <tr>
      <td><img src="http://forum.codecall.net/images/globalpos.jpg" width="241" height="53" /></td>
        <td height="83" colspan="3"><?php include_once("buttons.php")?></td> // this is a javascript file
      </tr>
      <tr>
        <td height="202"><?php include_once("ads.php")?></td> //this is a swf file
        <td colspan="2"><?php include_once("text_index.php")?></td> // plain text file
      </tr>
      <tr><td><?php include_once("show.php")?></td> //this is where i have problem lol -.-
      </tr>
    </table>
    thanks ^_^
    Last edited by hardinera; 02-16-2010 at 06:27 PM.

  10. #139
    Jaan Guest

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

    Code:
    <td><?php include_once("show.php")?></td>
    That's because.. when you include that file.. (show.php is created as an image) and if you include this other code also.. then it messes up the code.
    There can not be any output before header(); function but in your code.. there is so just change your code to:

    Code:
    <td><img src="show.php" alt="My Image" /></td
    and it should do the job

  11. #140
    hardinera's Avatar
    hardinera is offline Learning Programmer
    Join Date
    Jul 2009
    Posts
    42
    Rep Power
    0

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

    -.- that code never entered my mind -.-
    thanks for help jaan! really helped me a lot

Closed Thread
Page 14 of 22 FirstFirst ... 41213141516 ... LastLast

Thread Information

Users Browsing this Thread

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