php 从文本框中获取值

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10366761/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-24 22:00:59  来源:igfitidea点击:

Get value from textbox

php

提问by GuiceU

I want to get the value of a textbox in PHP, and when I try this:

我想在 PHP 中获取文本框的值,当我尝试这样做时:

<form method=post action="update.php">
<input type="text" name="Hex" />
<input type="submit" value="OK" />  
</form>
<?php
$test = $_POST['Hex'];
echo $test;
?>      

I just get the error:

我只是收到错误:

Undefined index: Hex

未定义索引:十六进制

I've Googled to no avail; so please someone, help me!

我用谷歌搜索无济于事;所以请有人帮助我!

回答by phsaires

I hope this help you:

我希望这对你有帮助:

    <?php
if (isset($_POST['submit'])) {
$test = $_POST['Hex'];
echo $test;
} else { ?>
<form method="post" action="">
<input type="text" name="Hex" />
<input type="submit" value="OK" name="submit" />  
</form>
<?php } ?>

回答by arun

i think the issue is with the quotation marks, @GuiceU you forgot to add the quotes to post.

我认为问题出在引号上,@GuiceU 您忘记添加要发布的引号。

Just replace your method = postwith method="post"

只需将您的方法 = post替换为method="post"

HTML code:

HTML代码:

<form method="post" action="update.php">
<input type="text" name="Hex" />
<input type="submit" value="OK" />  
</form>

php code:

php代码:

<?php
               $test = $_POST['Hex'];
               echo $test;
?>  

回答by Nauphal

Your code looks fine. Still, you can try this:

你的代码看起来不错。不过,你可以试试这个:

Make your form like this:

让你的表格像这样:

<form method="post" action="update.php">

and try to use $_REQUESTinstead of $_POST

并尝试使用$_REQUEST而不是$_POST

回答by Creative Solution

Use at the start of the script

在脚本开头使用

<?php error_reporting(E_ALL ^ E_NOTICE); ?>