DarnStuckAgain Posted April 8, 2012 Share Posted April 8, 2012 Not really sure how to get the images I have stored in MySQL into a html form. I can call-up the text fields from the database but it cannot seem to find the index for the images. Here is my code:- <?php session_start(); mysql_connect("localhost","root","abc") or die ("Error! Cannot connect to database"); mysql_select_db("theimageworks") or die ("Cannot find database"); $query = "SELECT * FROM jobs"; $result = mysql_query($query) or die (mysql_error()); ?> <?php //display data in html table echo "<table>"; echo "<tr><td>Username</td><td align='center'>Message</td><td>Product Image</td></tr>"; while($row = mysql_fetch_array($result)) { echo "</td><td>"; echo $row['username']; echo "</td><td>"; echo $row['message']; echo "</td></tr>"; echo $row['image']; } echo "</table>"; ?> The error message I get is "Notice: Undefined index: image in....." Thanks in advance! Quote Link to comment Share on other sites More sharing options...
chriscloyd Posted April 8, 2012 Share Posted April 8, 2012 are you actually trying to store an image in the database or just a link to the image its self? Quote Link to comment Share on other sites More sharing options...
dcro2 Posted April 8, 2012 Share Posted April 8, 2012 Well, it seems that the table `jobs` does not have an `image` field, so check that table. Shouldn't you be also be putting it in an <img> tag? Quote Link to comment Share on other sites More sharing options...
DarnStuckAgain Posted April 8, 2012 Author Share Posted April 8, 2012 Yes I am storing images in a database for learning purposes (I know it's not recommended). You were right I wrote the wrong table name sorry about that -.- The code is changed to this now :- echo "<img src='".$row['jobimage']."'>"; but I am getting a huge screen filled with random symbols like "HªG<Œ€:”®ì[vW¬¬e•™L¡K»Ô⩾y$M¹Q›owuŒ›Ir" Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted April 8, 2012 Share Posted April 8, 2012 What you are doing has been done countless times before. Please see replies #4 and #5 at the following link - http://www.phpfreaks.com/forums/index.php?topic=356903.msg1686788#msg1686788 Quote Link to comment Share on other sites More sharing options...
dcro2 Posted April 8, 2012 Share Posted April 8, 2012 If you'd rather not use another script for images, you could embed them into your page with the data URI scheme. There's obvious downsides to that though. echo "<img src='data:image/jpeg;base64,".base64_encode($row['jobimage'])."'>"; EDIT: just read that other post, that's one downside. Quote Link to comment Share on other sites More sharing options...
DarnStuckAgain Posted April 9, 2012 Author Share Posted April 9, 2012 Problem solved thanks guys! I used the base64_encode solution Quote Link to comment 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.