Welcome Guest, Not a member yet? Register   Sign In
insert image path to database id
#1

[eluser]Unknown[/eluser]
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
Code:
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
Code:
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($ad_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 $ad_id to match the ad id but i don't know how else to call it, it tried $_SESSION['id']; and it didn't work
any help is appreciated!

if i use INSERT INTO, i get this:
http://imageshack.com/a/img197/2893/yzst.jpg

if i use UPDATE, i get nothing in the cover column


Messages In This Thread
insert image path to database id - by El Forum - 02-04-2014, 05:41 PM
insert image path to database id - by El Forum - 02-04-2014, 05:53 PM
insert image path to database id - by El Forum - 02-04-2014, 08:15 PM



Theme © iAndrew 2016 - Forum software by © MyBB