gadgetster Posted February 4, 2014 Share Posted February 4, 2014 (edited) im trying to upload a cover image for a posting and it seems to go through but on the database i see one line that shows the path with all other rows empty and another column with all the rows filled out except the image one I have a function that adds the image when called function add_cover($id, $file_temp, $file_extn){ $file_path = 'images/cover/' . substr(md5(time()), 0, 10) . '.' . $file_extn; move_uploaded_file($file_temp, $file_path); mysql_query("UPDATE `classifieds` SET `cover` = '" . mysql_real_escape_string($file_path) . "' WHERE `id` = " . (int)$id); } and the the actual php page if (isset($_FILES['cover']) === true){ $allowed = array('jpg', 'jpeg', 'gif', 'png'); $file_name = $_FILES['cover']['name']; $file_size = getimagesize($_FILES['cover']['name']); $file_extn = strtolower(end(explode('.', $file_name))); $file_temp = $_FILES['cover']['tmp_name']; if(in_array($file_extn, $allowed) === true){ add_cover($_SESSION['id'], $file_temp, $file_extn); }else{ $errors[] = 'Incorrect file type. Only allowed: ' . implode(', ', $allowed) . ''; } } it won't work. i know it's probably the something to do with the way i am trying to get $_SESSION['id'] to match the ad id but i don't know how else to call that ad... any help is appreciated! ps. this is what happens when i use mysql_query("INSERT INTO `classifieds` (`cover`) VALUES ('$file_path')"); instead of the add_cover function: Edited February 4, 2014 by gadgetster Quote Link to comment https://forums.phpfreaks.com/topic/285926-image-path-inserting-into-database-on-the-same-column/ Share on other sites More sharing options...
gadgetster Posted February 5, 2014 Author Share Posted February 5, 2014 someone? Quote Link to comment https://forums.phpfreaks.com/topic/285926-image-path-inserting-into-database-on-the-same-column/#findComment-1467773 Share on other sites More sharing options...
jazzman1 Posted February 5, 2014 Share Posted February 5, 2014 Well, have you taken some debugging steps? Strart with php error_reporting functions and mysql_error. So on the top of your application php file put the following ini_set('display_errors', 1); ini_set('display_startup_errors', 1); ini_set('output_buffering', 'Off'); error_reporting(-1); And for debugging your query use mysql_error() function Something like $sql = "UPDATE `classifieds` SET `cover` = '" . mysql_real_escape_string($file_path) . "' WHERE `id` = " . (int)$id; $result = mysql_query($sql) or die('<pre> SQL: '.$sql .'ERROR: '. mysql_error() . '</pre>' ); Also, show us the string valueof $file_path and post the errors. Quote Link to comment https://forums.phpfreaks.com/topic/285926-image-path-inserting-into-database-on-the-same-column/#findComment-1467781 Share on other sites More sharing options...
gadgetster Posted February 6, 2014 Author Share Posted February 6, 2014 there are no errors showing.. i did what you said Quote Link to comment https://forums.phpfreaks.com/topic/285926-image-path-inserting-into-database-on-the-same-column/#findComment-1467901 Share on other sites More sharing options...
mac_gyver Posted February 6, 2014 Share Posted February 6, 2014 the code you have posted doesn't contain any code that is responsible for the title/price/description data, so it will be really hard to help you with what is wrong with your code. first, you need to define what your intent is. an INSERT query inserts a new row, an UPDATE query allows you to change values in an existing row. what are you trying to do? Quote Link to comment https://forums.phpfreaks.com/topic/285926-image-path-inserting-into-database-on-the-same-column/#findComment-1467902 Share on other sites More sharing options...
Solution gadgetster Posted February 6, 2014 Author Solution Share Posted February 6, 2014 somehow with your comment, i managed to find the mistake i made. when submitting the ad, i wasn't telling it to add the image to the database thanks for your help! Quote Link to comment https://forums.phpfreaks.com/topic/285926-image-path-inserting-into-database-on-the-same-column/#findComment-1467909 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.