Hi
I have a small MYSQL database that I'm trying to display an image. I modified some info I found online. It appears that the image is being inserted in the database - it's just my PHP to display it that's gone wrong.
I have a sign_up.html, sign_up.php, display_users.php, connect.php and image.php (which is where I think the error is). When I run display_users.php, it shows a placeholder for the image.
I've included some of the files - I'd appreciate any advice.
Also, while I started this project with the intention of saving the image as a BLOB, the info I found saved it as LONG TEXT. why is that?
I think you need to have the content-type defined.
In your case, jpeg ... instead of x-icon,gif, or png?
You say "favicon", but you aren't using .ico ?
PHP Code:
image.php
============================================
include('connect.php');
$id= $_REQUEST["id"];
$q = "SELECT ('favicon') FROM 'user' where id=".$id;
$result = mysql_query($q);
while ($row = mysql_fetch_array($result) ) {
$img = $row['favicon'];
}
header('Content-Type: image/jpeg');
// I'm not sure which one of these to use...
echo base64_decode($img);
//echo $img;
}
Thanks. Favicon probably should have been avatar - but I guess that's irrelevant.
The example I used - here - didn't need the datatype - and I verified this on my own system.
That is, unless my interpretation has gone awry.
*Using FF - I can see for the image placeholders, the path is - http://basil.x10.mx/bookmark/image.php?id=
That suggest to me that image.php isn't successfully appending the image id to each image. But I can't see why!
There is a risk to using $_REQUEST.
$_REQUEST has changed a bit during the last PHP revisions.
I'll bet that with your PHP version, in the config, it has been disabled along with register_global (as a default).
Use this instead ...
$id= $_GET["id"];
============================
If you are using a variable with a URL and you also sometimes use it with a <form method="post>,
you have to determine whether the variable is GET or POST. In the past, you could have used
REQUEST to cover either of them.
If $_REQUEST is disabled for you ...
PHP Code:
<?php
// The "old way" of doing it... // covers both GET and POST ... $action=$_REQUEST['action'];
// If REQUEST has been disabled, check for either one ... if(isset($_GET['action']){ $action=$_GET['action']; } if(isset($_POST['action']){ $action=$_POST['action']; }
Thank you. I changed that, but without success. The example I used from the web uses _REQUEST, and that tutorial does work.
It's only when I try to adapt it into my own implementation that it fails - operator error!!!!!
Something I've done is preventing the id being appended to the <img src ..> tag, giving me
Code:
http://basil.x10.mx/bookmark/image.php?id=
.
I tried comparing tags from mine to the tutorial, without success. The only other thing I can see that could be is the way I tried to concatenate the elements.
Thanks for taking the time.
When I use either of the methods you've suggested, I see the word favicon only (I'm guessing the alt tag).
If I leave it the way I had it, it's a broken image. There must be some other operator error hidden away.
__________________
Official BinPress hand picked coder.
For anyone worried about SQL injection go have a look at my small yet powerful script here.
Go Pledge for Light Table, if it hit's $300,000 Python and other languages will get added.
I am 1 of 65,608 people to get a Pebble Watch :P
Thanks - but again, if I use either "bits" of code supplied, it shows the word (alt tag?) favicon, rather than an image or even broken image.
I'm reposting my code, in case I've accidentally altered something. I've been through, and double checked what I've done, but I could easily be overlooking some glaring error.
PHP Code:
=====================================================
image.php
<?php
include('connect.php');
$id= $_GET['id'];
$q = "SELECT ('favicon') FROM 'user' where id = " . $id;
$result = mysql_query($q);
while ($row = mysql_fetch_array($result) ) {
$img = $row['favicon'];
}
echo base64_decode($img);
=========================================================
display_users.php
require ("connect.php");
// select our database
mysql_select_db("basil_bookmark") or die(mysql_error());
$result = mysql_query("SELECT * FROM user");
//Display Table
When I alter that, and call the line as you did, I see a whole bunch of code. (http://basil.x10.mx/bookmark/image.php?id=9)
If I then call the display_users.php file, it appends a number to the image - ie Src=http://basil.x10.mx/bookmark/image.php?id=9, but still you can only see the alt tag.
I think that narrows down the problem. To insert the images into the database, I used:
Like you mentioned earlier ... your problem is most likely in how you defined the column.
It has to be defined as a BLOB of some kind... in that example it's:
data` mediumblob NOT NULL,
Thank you. I did work through the thread you gave me. But couldn't apply it to my scenario. I suppose I could have just done a copy and paste, but I'm not sure what I would have learnt. Trawled the web and went back to this
And I think I'm a lot closer than I was. When I run display_users.php, I get a whole heap of code now. See here. I'm guessing that's cos of my header stuff, but I'm not sure.
Here's what my display_users.php looks like now.