问题描述
我正在制作一个 HTML 表单.我希望结果出现在 PHP 脚本中.
问题是我无法获得传递给 PHP 的值.如果我使用价值:
它总是传递引号中的文本.在这种情况下选择"
.如何从选项中传递其中一个字符串?
试试这个:
您的选择控件和提交按钮都具有相同的 name
属性,因此最后一个使用的是您单击它时的提交按钮.抛开所有其他语法错误.
check.php
<块引用>
关于使用原始 $_POST
数据的强制性免责声明.清理您将在应用程序逻辑中实际使用的任何内容.
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>
The problem is I cannot get the value passed to the PHP. if I use value:
<INPUT TYPE="submit" name="website_string" value="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.
check.php
<?php
echo $_POST['website_string'];
?>
Obligatory disclaimer about using raw
$_POST
data. Sanitize anything you'll actually be using in application logic.
这篇关于HTML 表单提交到 PHP 脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!