我有问题,我无法在数据库中插入标签。我有3个表: 制品
id title content date
标签
id name
Tags_in_news
id news_id tag_id
我的HTML:
<form id="form1" name="form1" method="post" action="<?php echo base_url() .'administration/addArticle'; ?>" enctype="multipart/form-data">
p><b>Title:</b></p>
<input type="text" name="title" id="title" style="width:605px">
<p><b>Tags:</b></p>
<input type="text" name="dropdiv" id="dropdiv" style="width:605" /><br />
<p><b>Content:</b></p>
<textarea name="content" id="content" style="width:605px; height: 300px;" rows="200"></textarea>
<input type="submit" value="Add" />
</form>
方法:
public function addArticle()
{
if ($this->input->post('title', TRUE) and($this->input->post('dropdiv',TRUE)) and strlen($this->input->post('title', TRUE))>3 )
{
$title = addslashes($this->input->post('title'));
$content = addslashes($this->input->post('content'));
$tags = $this->input->post('dropdiv');
$date = date("Y-m-d H:i:s");
$theid = $this->db->insert_id();
$this->db->query("
INSERT INTO articles (
title,
content,
date)
VALUES (?, ?, ?)",
array(
$title,
$content,
$date)
);
foreach ($tags as $t)
{
$tag_SQL = $t;
$this->db->query("insert into tags_in_news (news_id, tag_id) values ('{$theid}','{$tag_SQL}')");
}
redirect('administration/add_article', 'redirect');
}
}
在文章中没有问题数据存储,但在表中tags_in_news不存储,我无法理解问题出在哪里...请帮助