HTML表单提交给PHP脚本 [英] HTML form submit to PHP script

查看:140
本文介绍了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.

这篇关于HTML表单提交给PHP脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆