crankgeorge Posted September 30, 2014 Share Posted September 30, 2014 the script succesfuly insert image to the database bt, i cant be able to display it on my pages, any help i will appreciate saveimage.php images_tbl.php Quote Link to comment https://forums.phpfreaks.com/topic/291374-am-having-problem-displaying-image-from-my-database/ Share on other sites More sharing options...
ginerjm Posted September 30, 2014 Share Posted September 30, 2014 People usually post the RELEVANT code here on the forum instead of making us read thru entire scripts. Try it! Quote Link to comment https://forums.phpfreaks.com/topic/291374-am-having-problem-displaying-image-from-my-database/#findComment-1492468 Share on other sites More sharing options...
jcbones Posted October 1, 2014 Share Posted October 1, 2014 You would reverse the process that you used to insert the image NAME into the database. Your images are not in the database, they are in a folder named "images" that resides in your parent directory where this script is run from. So, you would need a select query from the database, to get the image names, then display them just like any other image. $sql = "SELECT images_path, userID, submission_date FROM images_tbl"; $result = mysql_query($sql) or trigger_error(mysql_error()); if(mysql_num_rows() > 0) { while($row = mysql_fetch_assoc($result)) { echo '<img src="images/' . $row['images_path'] . '" alt="Image" /><br />'; } } Now, this will get you the image from names from the database, and it will display them on a page, BUT do not ever use the code that you have posted. It is way to simplistic, open to all manners of evil by others. You will have a compromised database, and maybe even the whole server. You should be using MySQLi extension or PDO for database interaction. As well as proper sanitation/validation of all incoming data. Coupling that with proper escaping of your outgoing data.Basically, don't just copy paste code off the web, and get an application up and running. You are responsible for all data transfers from your site, and should take that responsibility with the utmost care. This guy has a pretty good write up on why your way is bad http://http://nullcandy.com/php-image-upload-security-how-not-to-do-it/ 1 Quote Link to comment https://forums.phpfreaks.com/topic/291374-am-having-problem-displaying-image-from-my-database/#findComment-1492534 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.