Jamied_uk Posted March 19, 2012 Share Posted March 19, 2012 hi i want to store url to images in database for logged in users (where id = $id) and recall the image hopefully using --------------------- <img src="<?php echo row['link']; ?>" /> or similar and need help with the sql update string any ideas please help i been stuck with this for some time and now decided to ask around in this forum for help, please help if you can. Link to comment https://forums.phpfreaks.com/topic/259263-store-image-path-in-mysql/ Share on other sites More sharing options...
Mahngiel Posted March 19, 2012 Share Posted March 19, 2012 then you need a method to store the filepath, filename, and file extension so it can be recalled. Link to comment https://forums.phpfreaks.com/topic/259263-store-image-path-in-mysql/#findComment-1329013 Share on other sites More sharing options...
AyKay47 Posted March 19, 2012 Share Posted March 19, 2012 hi i want to store url to images in database for logged in users (where id = $id) and recall the image hopefully using --------------------- <img src="<?php echo row['link']; ?>" /> or similar and need help with the sql update string any ideas please help i been stuck with this for some time and now decided to ask around in this forum for help, please help if you can. Again, don't necro old threads, create a new thread in the proper forum with your question. Link to comment https://forums.phpfreaks.com/topic/259263-store-image-path-in-mysql/#findComment-1329017 Share on other sites More sharing options...
SaCH Posted March 19, 2012 Share Posted March 19, 2012 Its very simple to store the image path into your mysql database. please consider this example. <?php //getting the filename of the image file. $filename = $_FILES["image"]["name"]; //directory name to be stored. $path = "data/mydata"; //uploading the image file with the image file name into the directory. if(move_uploaded_file($_FILES["image"]["tmp_name"],$path."/".$filename) { //if the image is stored success into the directory then we are going to store into database. //the real path with the filename. $mysql_path = $path."/".$filename; //sql query to be executed. $sql = "INSERT INTO `tablename`(`filename`,`path`) VALUES ('$filename','$mysql_path')"; //executing the query. if(mysql_query($sql)) { echo 'path inserted into database'; } else { echo 'path not inserted into database'; } } else { echo 'file not uploaded'; } ?> Link to comment https://forums.phpfreaks.com/topic/259263-store-image-path-in-mysql/#findComment-1329041 Share on other sites More sharing options...
Jamied_uk Posted March 19, 2012 Author Share Posted March 19, 2012 thank you i will try it now, just gotta edit some values, also is this line i changed ok my files are stored in /pics/ $path = "/pics/"; I assume this is ok but will now check, reason i ask is because i also assume i do not have to change this line, $mysql_path = $path."/".$filename; thanks for your reply again it was helpful. just checked the page but it is blank im missing the form part for file and submit, can you supply this as this is part the reason i have had issues because php and mysql parts are hard to find together for this task, i new the concept was easy but only if its all there. Link to comment https://forums.phpfreaks.com/topic/259263-store-image-path-in-mysql/#findComment-1329044 Share on other sites More sharing options...
SaCH Posted March 19, 2012 Share Posted March 19, 2012 yes you are right because //this variable contains only the directory path which the image file to be stored. So you don't need to put the "/" end of the path. $path = "/pics"; //this variable contains the joining of file name with its directory path to get the real path of the image file. So you don't have to edit this. $mysql_path = $path."/".$filename; //if you echo this line. echo $mysql_path; //the result will be. /pics/somefile.jpg Link to comment https://forums.phpfreaks.com/topic/259263-store-image-path-in-mysql/#findComment-1329052 Share on other sites More sharing options...
Jamied_uk Posted March 19, 2012 Author Share Posted March 19, 2012 the page is blank have you got a form part for the fil and submit part at all? Link to comment https://forums.phpfreaks.com/topic/259263-store-image-path-in-mysql/#findComment-1329056 Share on other sites More sharing options...
AyKay47 Posted March 19, 2012 Share Posted March 19, 2012 Why are you guys still necroing this old thread. Link to comment https://forums.phpfreaks.com/topic/259263-store-image-path-in-mysql/#findComment-1329057 Share on other sites More sharing options...
Jamied_uk Posted March 19, 2012 Author Share Posted March 19, 2012 because my friend it is better to have all the required info all on one page not throughout multiple posts, this may not be good for everyone but is most sensible and keeps posts to a minimum when you only reply with a question or an answer, not just for sake of posting. Link to comment https://forums.phpfreaks.com/topic/259263-store-image-path-in-mysql/#findComment-1329062 Share on other sites More sharing options...
Philip Posted March 19, 2012 Share Posted March 19, 2012 I've split the thread, please continue in this one. Link to comment https://forums.phpfreaks.com/topic/259263-store-image-path-in-mysql/#findComment-1329065 Share on other sites More sharing options...
SaCH Posted March 19, 2012 Share Posted March 19, 2012 the page is blank have you got a form part for the fil and submit part at all? Ok.. can you post your full code here ? Link to comment https://forums.phpfreaks.com/topic/259263-store-image-path-in-mysql/#findComment-1329079 Share on other sites More sharing options...
josephbupe Posted November 4, 2014 Share Posted November 4, 2014 Hi, I appreciate this post. My request is if someone can kindly update the code for MySQLi and maybe provide a full working code for someone like myself. Regards. Joseph Link to comment https://forums.phpfreaks.com/topic/259263-store-image-path-in-mysql/#findComment-1495659 Share on other sites More sharing options...
mac_gyver Posted November 4, 2014 Share Posted November 4, 2014 @josephbupe, programming help forums are not for getting people to write code for you. they are for getting help with code you are writing. if it's beyond your programming skills to do something that you want, you will need to hire someone to do it for you. if you do have your own programming that you have written and need help with, start your own thread for it. topic locked. Link to comment https://forums.phpfreaks.com/topic/259263-store-image-path-in-mysql/#findComment-1495669 Share on other sites More sharing options...
Recommended Posts