我是编码新手,我正在做一个汽车经销商网站。我正在做一个汽车信息表格,有多个选择和一个图像上传(基于 ajax 在 github 上得到它)。所以我需要将图像与汽车的其他信息联系起来。我的汽车信息表单在数据库中有一个自动增量 ID 行。所以我试图通过汽车 ID 将图像绑定到汽车(我希望每个上传的图像都有汽车 ID)。我有这个 mysql 插入代码,我想添加最后更新的表 id 的值(来自 car 表)并将 +1 添加到它。这是个好主意吗?还是我应该走另一条路?
我应该将它添加到下面代码的####### 空间中吗(我已经添加了 carID 行,并在代码中编写了它)?
Database: login, table: masinos
和图像表:files
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']
.'` (`carID`,`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;
}