开发者

How to display in my webpage picture saved in Mysql as Medium Blob?

So i have this code in the HTML:

 <img src="imagescript.php?id=1">

And i have this code in the imagescript.php :

<?php
    $servername="localhost";
    $username="root";
    $conn= mysql_connect($servername,$username)or die(mysql_error());
    mysql_select_db("licitatii",$conn);
    $sql="select picture from auctions where auction_id='$_GET[id]'";
    $result=mysql_query($sql,$conn) or die(mysql_error());
    $row = mysql_fetch_assoc($result);
    $image = $row['picture'];
    header("Content-type: image/jpeg");
    print $image;
 ?>

I have used this from instructions on the internet but my image doesn't display .

Is it possible that I have incorrectly uploaded the image?

I used < input name="regphoto" type="file" > in a method="POST" form and then inserted in the table the $_POST[regphoto]

If it helps you, here's the php script i used to insert the photo after clicking the submit button:

$sql="insert into auctions (auction_id,owner_id,parent_category_id,title,description,picture,postage,starting_price,buyout_price,end_date)values(NULL,'$ownerid','$parentcategoryid','$_POST[regtitle]','$_POST[regdescription]','$_POST[regphoto]','$_POST[regpostage]','$_POST[regstartingprice]','$_POST[regbuyoutprice]','$expiration')";

As u can see, I inserted into the "picture" column(type m开发者_Go百科ediumblob) the value $_POST[regphoto]


A few comments that might help:

  1. You probably need to login to the mysql server with a password (although not necessarily...).
  2. You need to protect your code from sql injection attacks, the easiest way in your case would be something like $id = (int) $_GET[id] and use $id in your query.
  3. You will have to post the php code you used to insert the image as well, as inserting $_POST[photo] sounds wrong: You need $_FILES['photo'] and that is an array, see the manual.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜