need help so database will work with jquery file upload

Guys I am really struggling its been a while since I last used PHP and MySQL. I need to add userID, and listingID which are both saved as session variables, Into the following insert code so when the script runs it adds them into the database. Note the script as it is works i just cant work out where to add them.
[php]<?php
session_start();
$userID = $_SESSION[‘userID’];
$listingID = $_SESSION[‘listingID’];

$options = array(
‘delete_type’ => ‘POST’,
‘db_host’ => ‘localhost’,
‘db_user’ => ‘root’,
‘db_pass’ => ‘’,
‘db_name’ => ‘members’,
‘db_table’ => ‘files’
);

error_reporting(E_ALL | E_STRICT);
require(‘UploadHandler.php’);

class CustomUploadHandler extends UploadHandler {

protected function initialize() {
    $this->db = new mysqli(
        $this->options['db_host'],
        $this->options['db_user'],
        $this->options['db_pass'],
        $this->options['db_name']
    );
    parent::initialize();
    $this->db->close();
}

protected function handle_form_data($file, $index) {
    $file->title = @$_REQUEST['title'][$index];
    $file->description = @$_REQUEST['description'][$index];
}

protected function handle_file_upload($uploaded_file, $name, $size, $type, $error,
        $index = null, $content_range = null) {
    $file = parent::handle_file_upload(
        $uploaded_file, $name, $size, $type, $error, $index, $content_range
    );
    if (empty($file->error)) {
        $sql = 'INSERT INTO `'.$this->options['db_table']
            .'` (`name`, `size`, `type`, `title`, `description`)'
            .' VALUES (?, ?, ?, ?, ?)';
        $query = $this->db->prepare($sql);
        $query->bind_param(
            'sisss',
            $file->name,
            $file->size,
            $file->type,
            $file->title,
            $file->description
        );
        $query->execute();
        $file->id = $this->db->insert_id;
    }
    return $file;
}

protected function set_additional_file_properties($file) {
    parent::set_additional_file_properties($file);
    if ($_SERVER['REQUEST_METHOD'] === 'GET') {
        $sql = 'SELECT `id`, `type`, `title`, `description` FROM `'
            .$this->options['db_table'].'` WHERE `name`=?';
        $query = $this->db->prepare($sql);
        $query->bind_param('s', $file->name);
        $query->execute();
        $query->bind_result(
            $id,
            $type,
            $title,
            $description
        );
        while ($query->fetch()) {
            $file->id = $id;
            $file->type = $type;
            $file->title = $title;
            $file->description = $description;
        }
    }
}

public function delete($print_response = true) {
    $response = parent::delete(false);
    foreach ($response as $name => $deleted) {
        if ($deleted) {
            $sql = 'DELETE FROM `'
                .$this->options['db_table'].'` WHERE `name`=?';
            $query = $this->db->prepare($sql);
            $query->bind_param('s', $name);
            $query->execute();
        }
    } 
    return $this->generate_response($response, $print_response);
}

}

$upload_handler = new CustomUploadHandler($options);
?>[/php]

this is where the INSERT code is

[php]
if (empty($file->error)) {
$sql = ‘INSERT INTO '.$this->options['db_table'] .' (name, size, type, title, description)’
.’ VALUES (?, ?, ?, ?, ?)’;
$query = $this->db->prepare($sql);
$query->bind_param(
‘sisss’,
$file->name,
$file->size,
$file->type,
$file->title,
$file->description
);
$query->execute();
$file->id = $this->db->insert_id;
}
return $file;
}
[/php]

I have tried everything and i know I am overlooking something small.

I’m going to guess you need to add it to the insert portion of the code.

I am going to guess that [member=72272]astonecipher[/member] is right.

Did you add the two columns to the database? That would be your first step.

Sponsor our Newsletter | Privacy Policy | Terms of Service