HTML表单提交给PHP脚本

问题描述:

我正在制作HTML表单。我希望结果出现在PHP脚本中。

I am making an HTML form. I want the results to appear in the PHP script.

<form action="chk_kw.php" method="post"> <br />
    <select> name="website_string" 
        <option value="" selected="selected"></option>
    <option VALUE="abc"> ABC</option>
    <option VALUE="def"> def</option>
        <option VALUE="hij"> hij/option>   
    </select>
    <input type="submit" name="website_string"  >
</form>

问题是我无法获得传递给PHP的值。如果我使用值:

The problem is I cannot get the value passed to the PHP. if I use value:

<INPUT TYPE="submit" name="website_string" value="selected" >

它总是传递引号中的文字。在这种情况下selected。我如何传递选项中的一个字符串?

It always passes the text in the quotes. In this case "selected". How do I pass one of the strings from the option?

试试这个:

Try this:

<form method="post" action="check.php">
    <select name="website_string">
        <option value="" selected="selected"></option>
        <option VALUE="abc"> ABC</option>
        <option VALUE="def"> def</option>
        <option VALUE="hij"> hij</option>
    </select>
    <INPUT TYPE="submit" name="submit" />
</form>

您的选择控件和您的提交按钮具有相同的名称属性,所以最后一个使用的是点击它时的提交按钮。除了所有其他的语法错误。

Both your select control and your submit button had the same name attribute, so the last one used was the submit button when you clicked it. All other syntax errors aside.

<?php
    echo $_POST['website_string'];
?>




关于使用raw $ _POST 数据。 清理您在应用程序逻辑中实际使用的任何内容

Obligatory disclaimer about using raw $_POST data. Sanitize anything you'll actually be using in application logic.