【发布时间】:2012-04-08 22:06:04
【问题描述】:
我有一个包含主题列表的复选框。在我的用户注册后,他们可以选择一个主题列表,然后将其放入表格中。目前我有代码可以找到他们的 member_id 并将其添加到表中。但我不确定如何处理用户选择的主题,然后将其添加到用户 member_id 的兴趣表中。
我知道我需要使用 for 循环来处理 member_id 和 topic_id 并将每个选择的选项添加到表中。但我不知道该怎么做。这是我的代码。
这是我的表格
</form>
<form method="post" action="topic.php">
<input type="checkbox" name="topic[]" value="1"> artificial intelligance
<input type="checkbox" name="topic[]" value="2"> computer graphics
<input type="checkbox" name="topic[]" value="3"> computer animation
<input type="submit" name="submit" value="submit topic">
</form>
这两个找到member_id和topic_id
// 查找成员ID
$query = "SELECT member_id FROM member where username = '$un'";
$result = mysql_query($query) or die ("query failed: " . mysql_error());
$row = mysql_fetch_array($result, MYSQL_ASSOC);
$username=$row['member_id'];
//find the topic id
$query = "SELECT topic_id FROM topic WHERE topic_name ='$interest'";
$result = mysql_query($query) or die ("query failed: " . mysql_error());
$row = mysql_fetch_array($result, MYSQL_ASSOC);
$topic_id=$row['topic_id'];
【问题讨论】:
-
如果我错了,请纠正我......您需要知道谁来处理您的表单以将信息保存在您的数据库中,其中主题可以是一个或多个???
-
我想知道如何将 member_id 和 topic_id 保存到一个表中,但是用户可以选择很多主题,所以我需要能够插入很多记录