如何将数据从该页面传送到另一页面?示例我有一个名为create.php
的视图页面,并且在这里插入了一些值
<div class="form-group">
<label>Body</label>
<textarea class="form-control" name="body" placeholder="Ask Somenthing..."></textarea>
</div>
现在,我希望将插入的值用于另一个视图页(suggestion.php
),而无需将其插入数据库中。
Ps。 suggestion.php
是可以将create.php
中的数据插入数据库的人。
有可能吗?谁能告诉我这样做的方法?
答案 0 :(得分:0)
要在页面之间传递数据,您可以重写现有的HTML,以使文本区域位于表单内。
<!-- create.php -->
<form method='post' action='suggestion.php'>
<label for='body'>Body</label>
<textarea class='form-control' name='body'></textarea>
<input type='submit' name='submit'>
</form>
然后,提交表单时,将触发表单的action参数-将您发送到suggestion.php
。在下一个文件中,您可以执行以下操作来检索输入到文本区域中的信息。
// suggestion.php
if (isset($_POST['body'])) {
// corresponds to the 'name' attribute of the inputs
echo $_POST['body'];
}
以上内容将回显到suggestion.php
页上,而不管放在文本区域中的内容如何。在第一页上输入的信息现在在第二页上可用,因此您可以根据需要使用它-现在可以非常容易地使用此变量将其插入数据库中。