日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

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

發布時間:2023/12/9 数据库 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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

總結

以上是生活随笔為你收集整理的php mysql insert 变量,php – 在blueimp / jquery-file-upload上添加更多自定义变量给mysql insert...的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。