runnerpaul Posted December 6, 2010 Share Posted December 6, 2010 Hi, Im trying to get an image to display from a reference in the database but am having no joy. At the minute Im just playing about with PHP to get familiar with it so you can ignore most of the code. The line im interested in is: <td><?php echo "<img src=\"C:\wamp\www\fermpix\Pics\'{$row["Name"]}'\">";?></td> When I view the page in my browser I see the attached. Can anybody see what im doing wrong? Heres the full page: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>Browse Upload Files</title> </head> <body bgcolor="white"> <?php error_reporting(E_ALL); include 'db.inc'; $query = "SELECT ID, Name, Path, Date, Description FROM Pics"; if (!($connection = @ mysql_pconnect($hostName, $username, $password))) showerror(); if (!mysql_select_db("fermpics", $connection)) showerror(); if (!($result = @ mysql_query ($query, $connection))) showerror(); ?> <h1>Image database</h1> <h3>Click <a href="insert.php">here</a> to upload an image.</h3> <?php //require 'disclaimer'; if ($row = @ mysql_fetch_array($result)) { ?> <table> <col span="1" align="right"> <tr> <th>File Name</th> <th>Date</th> <th>Image</th> </tr> <?php do { ?> <tr> <td><?php echo "{$row["Name"]}";?></td> <td><?php echo "{$row["Date"]}";?></td> <td><?php echo "<img src=\"C:\wamp\www\fermpix\Pics\'{$row["Name"]}'\">";?></td> </tr> <?php } while ($row = @ mysql_fetch_array($result)); ?> </table> <?php } // if mysql_fetch_array() else echo "<h3>There are no images to display</h3>\n"; ?> </body> </html> I would appreciate any help. Cheers Paul [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/220876-image-wont-display/ Share on other sites More sharing options...
phprocker Posted December 6, 2010 Share Posted December 6, 2010 This: <?php echo "<img src=\"C:\wamp\www\fermpix\Pics\'{$row["Name"]}'\">";?> needs to be this: <?php echo "<img src=\"C:\wamp\www\fermpix\Pics\\" . $row['Name'] . "\">"; ?> Respond if it doesn't work. Quote Link to comment https://forums.phpfreaks.com/topic/220876-image-wont-display/#findComment-1143747 Share on other sites More sharing options...
phprocker Posted December 6, 2010 Share Posted December 6, 2010 I just fixed an error I saw i had...check to make sure you have this... <?php echo "<img src=\"C:\wamp\www\fermpix\Pics\\" . $row['Name'] . "\">"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/220876-image-wont-display/#findComment-1143748 Share on other sites More sharing options...
runnerpaul Posted December 6, 2010 Author Share Posted December 6, 2010 Hey, thanks for the quick response. What did you change there? I still get the same result with both pieces pf code(no image). Quote Link to comment https://forums.phpfreaks.com/topic/220876-image-wont-display/#findComment-1143750 Share on other sites More sharing options...
runnerpaul Posted December 6, 2010 Author Share Posted December 6, 2010 Sorry, that was incorrect. With your first piece of code I get the same as in my screenshot. With your second I get: Parse error: parse error, expecting `','' or `';'' in C:\wamp\www\fermpix\index.php on line 53 Quote Link to comment https://forums.phpfreaks.com/topic/220876-image-wont-display/#findComment-1143751 Share on other sites More sharing options...
Pikachu2000 Posted December 6, 2010 Share Posted December 6, 2010 Give this a try: <?php echo "<img src=\"/www/fermpix/Pics/{$row['Name']}\">"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/220876-image-wont-display/#findComment-1143753 Share on other sites More sharing options...
runnerpaul Posted December 6, 2010 Author Share Posted December 6, 2010 Lol. Apologies. Didnt mean it like that. I appreciate any help as I havnt looked at PHP in years. I got rid of my error from the second piece of code you give me. It was due to a mistake I made. Still not getting any image displayed though. Quote Link to comment https://forums.phpfreaks.com/topic/220876-image-wont-display/#findComment-1143758 Share on other sites More sharing options...
Pikachu2000 Posted December 7, 2010 Share Posted December 7, 2010 Look at the html source. If you're not using the example I posted, I'd imagine the <img tag is malformed. Quote Link to comment https://forums.phpfreaks.com/topic/220876-image-wont-display/#findComment-1143771 Share on other sites More sharing options...
hennzo Posted December 7, 2010 Share Posted December 7, 2010 Hi, the easiest way is to use a relative link. instead of write this: <?php echo "<img src=\"C:\wamp\www\fermpix\Pics\'{$row["Name"]}'\">";?> ----------------------------------------------- Write this: <?php echo "<img src=\"/fermpix/Pics/{$row["Name"]}\" />";?> if your DOCUMENT_ROOT is "C:\wamp\www" <?php echo "<img src=\"/Pics/{$row["Name"]}\" />";?> if your DOCUMENT_ROOT is "C:\wamp\www\fermpix" or simply <?php echo "<img src=\"Pics/{$row["Name"]}\" />";?> if your Pics is your image folder and it is located in the same level as your PHP file. Quote Link to comment https://forums.phpfreaks.com/topic/220876-image-wont-display/#findComment-1143780 Share on other sites More sharing options...
runnerpaul Posted December 7, 2010 Author Share Posted December 7, 2010 Ah. <?php echo "<img src=\"/fermpix/Pics/{$row["Name"]}\" />";?> worked. Cheers for all the help guys. I was really starting to crack up. Quote Link to comment https://forums.phpfreaks.com/topic/220876-image-wont-display/#findComment-1143886 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.