我有两个div,每个div都包含自己的tinymce编辑器示例和隐藏的输入值:
<form method="post">
<div class="col-lg-12 fullWidth" id="full">
<input type="hidden" name="fullWidth" value="">
<div class="fullContent" style="background-color: white; height: 100%;">
<input type="hidden" name="panel" value="1">
<textarea class="original" id="mytextarea3" name="fullText">Some Text Here</textarea><!--I want to save this content along with panel_type_id = 1-->
<input type="submit" value="Save Content">
</div>
</div>
<div class="col-lg-12 halfWidth" id="half">
<input type="hidden" name="halfWidth" value="">
<div class="halfContent" style="background-color: white; height: 100%;">
<input type="hidden" name="panel" value="2">
<textarea class="original" id="mytextarea4" name="halfText">Some Text There</textarea><!--I want to save this content along with panel_type_id = 2-->
<input type="submit" value="Save Content">
</div>
</div>
</form>
如您所见,fullwidth div的“panel”值应为“1”,而halfwidth div的“panel”值应为“2”。一旦输入了文本,用户点击save,就会有一个小表单,用户可以在其中输入页面的标题,它还可以从url中的“value”捕获“pagetype”。这可以很好地工作,但在表单提交时,我还希望继承上面每个div的textarea的内容和“panel”值。这里的形式,但我不知道如何处理多种面板类型和内容。
<form action="addPage.php" method="post">
<input type="hidden" name="pageType" value="<?php echo $value;?>">//This comes from the url value
<input type="hidden" name="panel" value="">
<input class="form-control" id="addTitle" name="addTitle"><!--Page Title-->
<input type="submit" name="Save Page">
问题是,当我现在调用addpage.php脚本来插入记录时,我不知道如何正确地传递这些值,因此我添加了一个页面记录(page\u type\u id和title的$value),但随后为文本区域插入了两个内容和面板记录。
对于上述代码,我希望插入以下代码:
pages
ID | Title | page_type_id
1 | TitleNew | 1 /*this comes from $value*/
content
ID | Content
1 | Some Text Here
2 | Some Text There
panels
ID | panel_type_ID | page_id | content_id
1 | 1 | 1 | 1
2 | 2 | 1 | 2
这适用于所有3个表中的一次插入,但如果我可以为每个div设置多个面板类型,如何修改它以仍然插入一页记录,但成功地说明多个面板和内容?
下面是添加页面脚本
//This works for one record, but I think I need to add some kind of foreach or while into the insert for content and panel
//Insert Page
$title = $_POST['addTitle'];
$page_type = $_POST['pageType'];
$addpage = "
INSERT INTO pages (title, page_type_id)
VALUES ('$title','$page_type');
";
$mysqlConn->query($addpage)
$page_id = $mysqlConn->insert_id;
foreach(//panel and content){
//Insert Content
$content = $_POST['page_content'];
$addContent = "
INSERT INTO content(content)
VALUES('$content');
";
$mysqlConn->query($addContent);
$cont_id = $mysqlConn->insert_id;
//Insert panel(s)
$panelID = $_POST['panelType'];
$addPanel = "
INSERT INTO panels(panel_type_id, page_id, cont_id)
VALUES ('$panelID', '$page_id', '$cont_id');
";
$mysqlConn->query($addPanel);
}
暂无答案!
目前还没有任何答案,快来回答吧!