php mysql insert 变量,php – 在blueimp / jquery-file-upload上添加更多自定义变量给mysql insert...

我目前正在通过mysql在blueimp / jquery-file-upload脚本中插入标题和描述.我使用this教程让我在那里,但是,我需要添加另一个变量.该变量是当前登录用户的ID $_SESSION [“userid”]的会话,我想将其插入到我添加的名为uid的列中.通常很容易将另一列插入到插入中,但是这个脚本非常敏感,任何时候我都搞乱它,即使是最轻微的一点,我得到“SyntaxError:Unexpected token

/server/php/index.php

$options = array(

'delete_type' => 'POST',

'db_host' => 'localhost',

'db_user' => 'fpform_fanuser',

'db_pass' => '*****',

'db_name' => 'fpform_fandata',

'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);

解决方法:

假设您要更改INSERT查询(您发布的代码中只有一个INSERT查询),这是您需要更改的内容:

if (empty($file->error)) {

$sql = 'INSERT INTO `'.$this->options['db_table']

.'` (`name`, `size`, `type`, `title`, `description`, `uid`)'

.' VALUES (?, ?, ?, ?, ?, ?)';

$query = $this->db->prepare($sql);

$query->bind_param(

'sisss',

$file->name,

$file->size,

$file->type,

$file->title,

$file->description,

$_SESSION['userid']

);

$query->execute();

$file->id = $this->db->insert_id;

}

标签:blueimp,php,jquery,mysql

来源: https://codeday.me/bug/20191007/1864844.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值