Crazy Horse
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.
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?
Then I could just add something like :
assuming that my hidden field had a name of productID
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;
}
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];
Then I could just add something like :
$file->productID = @$_REQUEST['productID'][$index];
assuming that my hidden field had a name of productID
Right!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks Ray,
I was actually trying to modify this:
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!
I was actually trying to modify this:
https://blueimp.github.io/jQuery-File-Upload/
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!
ASKER
That's a great script, Ray! I am pretty sure I will use it for file uploads going forward.