Why isn't my image showing up?

前端 未结 1 1330
礼貌的吻别
礼貌的吻别 2021-01-29 12:48

-------EDIT-------
hi guys, seeing that you solved this problem for me, i thought it would be a good idea to solve the same problem again but on a different page. i cannot

1条回答
  •  粉色の甜心
    2021-01-29 13:15

    You are not setting the correct Content-type header before echoing out the image data.

    You MUST also escape the $_GET['id'] parameter.

    // Escape $id
    $id = mysql_real_escape_string($_GET['id']);   
    
    $link = mysql_connect($host, $user, $passwd);
    mysql_select_db($dbName);
    
    // Use the escaped $id
    $query = "SELECT picture FROM products WHERE serial='$id'";
    $result = mysql_query($query,$link);
    
    if ($result) {
      $row = mysql_fetch_assoc($result);
    
      // Set the Content-type
      // This assumes image/jpeg. If you have different image types,
      // you'll need logic to supply the correct MIME type
      // image/jpeg image/png image/gif, etc
      header("Content-type: image/jpeg");
      echo $row['picture'];
    }
    ?>
    

    In your main script, it looks like you are merely missing an echo

            '
            // Should be
            '
            // ------^^^^^^
    

    0 讨论(0)
提交回复
热议问题