I have a the following code that i intend to should return a filepath name from mysql in the php section and then display the image in html. But i am only getting up a tiny thumbnail in my browser. By the way “username” and “imagefile” are the only columns in the table “images”.
I’m sure there is just some silly mistake but i need a fresh pair of eyes to spot it. Thanks a lot in advance. P.S i know i should really me moving over to mysqli but i will simply translate at a later date. Cheers
<?php
session_start();
$username = $_SESSION['username'];
$con = mysql_connect('localhost','root','password');
mysql_select_db("db");
$profileimage = mysql_query("
SELECT * FROM images WHERE username='$username'
");
$row = mysql_fetch_array($profileimage);
$showimage = $row['imagefile'];
?>
<html>
<img src = "$showimage">
</html>
First off, HTML doesn’t know what
"$showimage"means. That is a PHP variable and HTML cannot interpret it. You need to output it so that HTML can just deal with the result.So if the value for
$showimageis"/images/foo.jpg"you would need something like:which would give you
Now, switching things to mysqli is as simple as replacing
mysqlwithmysqli. It’s no more complicated than that. Since it looks like you are just starting to learn about these things you may as well, when you go to improve things, learn about PDO.