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

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($ad_id, $file_temp, $file_extn);
     $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:

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

I'm just curious why you are using CI, but not really "using" it? You are still manually running queries instead of using the database class and not using CI's upload helper which makes this a lot easier.

You say "i know it’s probably the something to do with the way i am trying to get $ad_id" but the code you posted doesn't show where you are getting that value from.


I haven't got to using the catergory_id database yet as i thought it would be easier to start with first posting the ads then later put them in categories.

what is this upload helper? not really sure how i would use it for my website

and i am aware that $ad_id isn't being reference from anywhere, that is my question, how do i reference it from the database once the ad for is posted?

Theme © iAndrew 2016 - Forum software by © MyBB