[英]jQuery-File-Upload (blueimp) - how do I access the error value both in JS end and PHP
[英]how do I insert data when the DB value of “position” is equal to “id” in jquery-file-upload
在jquery-file-upload中,當“ position”的DB值等於“ id”時,如何插入數據,謝謝
if (empty($file->error)) {
$sql = 'INSERT INTO `'.$this->options['db_table']
.'` (`name`, `size`, `type`, `title`, `description`, `position`)'
.' VALUES (?, ?, ?, ?, ?, ?)';
$query = $this->db->prepare($sql);
$query->bind_param(
'sisssi',
$file->name,
$file->size,
$file->type,
$file->title,
$file->description,
$file->position
);
$query->execute();
$file->id = $this->db->insert_id;
}
return $file;
您應該分兩個步驟進行操作:
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(
$file->name,
$file->size,
$file->type,
$file->title,
$file->description
);
$query->execute();
$file->id = $this->db->insert_id;
$sql = 'UPDATE `'.$this->options['db_table']
.'` SET `position` = `id` WHERE `id` = ?';
$query = $this->db->prepare($sql);
$query->bind_param(
$file->id
);
$query->execute();
}
return $file;
首先插入沒有位置的位置,然后根據最后插入的ID更新位置。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.