【发布时间】:2011-11-28 12:26:09
【问题描述】:
我正在尝试制作 3 个表格标签系统。我在 mysql 中有 3 个表:
#Articles#
id
article
content
#Tags#
tag_id
tag (unique)
#tagmap#
id
tag-id
articleid
在我的提交 php 中我有:
$tags= explode(',', strtolower($_POST['insert_tags']));
for ($x = 0; $x < count($tags); $x++) {
//Add new tag if not exist
$queryt = "INSERT INTO `tags` (`tag_id`, `tag`) VALUES ('', '$tags[x]')";
$maket = mysql_query($queryt);
//Add the relational Link, now this is not working, beacasue this is only draft
$querytm = "INSERT INTO `tagmap` (`id`, `tagid`, `articleid`) VALUES ('', (SELECT `tag_id` FROM `tags` WHERE tag_id = "$tags[x]"), '$articleid')";
$maketm = mysql_query($querytm);
}
当我向文章提交新标签时,这不起作用。 Mysql 不会在我的 Tags 表中创建新标签。
PS。抱歉英语不好。
【问题讨论】:
-
有什么问题?您收到错误消息吗?您是否尝试过回显您的代码正在创建的查询?顺便说一句,您需要确保您不会受到 SQL 注入的影响(搜索 SO 或使用您最喜欢的搜索引擎了解更多信息)。
-
当我添加新帖子时,我没有收到错误。帖子已正常添加,但未添加标签。我知道 SQL 注入,但这是草稿版本。