开发者

How to process a value form a dropdown form item in PHP

I have the following issue regarding PHP. First off, I barely know some aspects of PHP, so excuse the newb question.

I'm working on a thing that outputs a little snippet of code so a friend of mine can update his website without coming to me for help. Depending on the situation he could have different option for this,开发者_高级运维 options that output different snippets. I create a selection form(dropdown) and the values for each is like this: $option1, $option2 & $option3. Then I made something like $example = $_REQUEST['selectionform']; that catches the value selected. My problem is that when I echo $example I get only "$option1" as text, and $option1 does not get processed as it would have if I'd echo it directly. I really hope that you understand what I'm saying, I have no idea about PHP syntax and terminology.

Do you have any idea how to get the option selected in the form to get processed as if I would echo that value directly?

Thank you


I think the problem is that you're not echoing the value through php, you're explicitly placing it within the page. Assuming $optionN are variabels you have in PHP, try the following:

<select name="foo">
  <option value="<?php echo $option1; ?>">option 1</option>
  <option value="<?php echo $option2; ?>">option 1</option>
  <option value="<?php echo $option3; ?>">option 1</option>
</select>


It sounds like you could be echoing the variable like this:

echo '$option1';

Which wouldn't output the string while in single quotes. Try:

echo "$option1";

or

echo $option1;

Remember also to echo inside of PHP tags.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜