How do you retrieve images with PHP & MySQL?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Andrew Jiang
    New Member
    • Dec 2010
    • 3

    #1

    How do you retrieve images with PHP & MySQL?

    Hi,

    I want to make a site where the user can "adopt" an image and have their own URL for each image, but the image would change varying on how many "clicks" they are given (which I already made, so that the number of "clicks" gets added by one every time some one visits.)
    There were no error given, but it doesn't display my image
    I want the link in the end become /image.php?id=1 (or something similar)

    This is my source code:

    Code:
    <?php
    
    include 'config.php';
    
      $id = $_GET['id'];
    
    
    if($id != "" && $id != "0"){
    	
    	if(is_numeric($id)){
    	
      if(abs($id) != $id) {
      
      }
    
    $query="SELECT * FROM owned_adopts WHERE aid='$id'";
    $result=@mysql_query($query);
    $num=@mysql_numrows($result);
    
    //Loop out code
    $i=0;
    while ($i < 1) {
    $oid=@mysql_result($result,$i,"oid");
    $clicks=@mysql_result($result,$i,"clicks");
    
    $i++;
    } 
      
    $query="SELECT * FROM adopts WHERE nid='$oid'";
    $result=@mysql_query($query);
    $num=@mysql_numrows($result);
    
    //Loop out code
    $i=0;
    while ($i < 1) {
    $begin=@mysql_result($result,$i,"begin");
    $image=@mysql_result($result,$i,"image");
    $mclicks=@mysql_result($result,$i,"mclicks");
    
    $i++;
    }
    
    if($nid == $oid){
    
    if($mclicks > $clicks){
    
    }
    else if($mclicks < $clicks){
    
      header("Content-type: image/PNG");
      echo $image;
      
    }
    else if($mclicks == $clicks){
    
    }
    else { }
    
    }
    else { }
      
      
      
      exit();
      
    	}
    	else { }
    
    }
    else { }
    
    ?>
    If you can, could you make the change adaptive to mine so it looks like it's been altered, so I could see what my mistakes are. Thanks! :)
  • Andrew Jiang
    New Member
    • Dec 2010
    • 3

    #2
    after I added the
    Code:
    $nid=@mysql_result($result,$i,"nid");
    because I noticed that was missing, i went to the webpage again and it said

    Code:
    The image "image.php?id=1" cannot be displayed because it contains errors.
    now it says that. Do you think it's a MySQL error or my PHP error? The IDs are SUPPOSED to be exactly the same, but it could not retrieve it. Could someone help me?

    Comment

    • Dormilich
      Recognized Expert Expert
      • Aug 2008
      • 8694

      #3
      two things come to mind:
      - stop using error suppression (it eats performance and error messages)
      - stop using the outdated mysql_* functions, rather use PDO or MySQLi

      Comment

      Working...