Link to home
Start Free TrialLog in
Avatar of Crazy Horse
Crazy HorseFlag for South Africa

asked on

add new field to OOP code in order to insert into new database column

I haven't got onto OOP yet but I am trying to use a multiple file upload script which uses OOP. This script currently uploads files to a specific directory and stores details in the database.

The problem is that I want to add another field but don't know how. I would like to add a product id. The product id is going to be in a hidden field.

 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;
    }

Open in new window


Besides obviously changing the SQL query and adding the product id, I need to know how to actually grab the posted variable.

Would it be here?

 $file->title = @$_REQUEST['title'][$index];
 $file->description = @$_REQUEST['description'][$index];

Open in new window


Then I could just add something like :

 $file->productID = @$_REQUEST['productID'][$index];

Open in new window


assuming that my hidden field had a name of productID
Avatar of Mukesh Yadav
Mukesh Yadav
Flag of India image

Right!
ASKER CERTIFIED SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Crazy Horse

ASKER

Thanks Ray,

I was actually trying to modify this:

https://blueimp.github.io/jQuery-File-Upload/

Open in new window


as it has a nice user interface and progress bars/multiple file upload etc.

But I just found something else lightweight that I might use instead. (dropzonejs) Especially since you said $_REQUEST is a bad idea!
That's a great script, Ray! I am pretty sure I will use it for file uploads going forward.