简体   繁体   English

PHP下拉列表。 保存数据以表单形式发布到其他页面

[英]PHP Drop down List . Saving data to post on other pages in form

I have been searching for an answer to this for the last two days. 最近两天,我一直在寻找答案。 I am trying to add a list of manufacturers to an existing form in php. 我试图将制造商列表添加到php中的现有表单中。 This worked out ok and I got it to work somewhat. 这样就可以了,我可以正常工作了。

Here is the problem when the user makes the selection and submits the form it takes them to another page that shows them a preview of their post. 当用户进行选择并提交表单时,这是一个问题,该表单会将他们带到另一个页面,该页面向他们显示其帖子的预览。 In this preview it show them the manufacturer they selected. 在此预览中,向他们显示了他们选择的制造商。 But when they finalize the the post it doesn't show using the same code. 但是,当他们最终确定帖子时,不会使用相同的代码显示出来。

I know that their must be a simple way of doing this. 我知道他们一定是这样做的简单方法。 I am not great with php but I have put forth a valiant effort to get this done. 我对php不太满意,但是我付出了英勇的努力来做到这一点。 I am stumped please help. 我感到难过,请帮忙。

Here is my code. 这是我的代码。

HTML: HTML:

<select action="select.php" name="manufacturer">
    <option value="Lincoln">Lincoln</option>
    <option value="Example">Example</option>
    </select>

PHP: PHP:

<?php
if(isset($_POST['manufactuer']))
echo "Manufacturer: ".$_POST['manufacturer'];
  else {?>

I call to the selection with this. 我以此来呼吁选择。

<?php echo "Manufacturer: ".$_POST['manufacturer']; ?>

How do I show this when the user posts and if the same user posts again or a different user posts to show their selections for those specific posts. 当用户发帖以及同一用户再次发帖或其他用户发帖以显示其对那些特定帖子的选择时,如何显示此信息。 posts 帖子

您可以将变量从“查看”页面传递到带有隐藏字段的下一页。

<form><input type='hidden' value='<?php echo $_POST['manufacturer']; ?>' name='manufacturer' /></form>

Just set the selected="selected" option in the selected select with php. 只需在php选择的选择中设置selected="selected"选项即可。 That makes: 这使得:

<option value="Lincoln" selected="selected">Lincoln</option>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM