Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/80.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/opengl/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 显示所选按钮值_Php_Html_Post_Get - Fatal编程技术网

Php 显示所选按钮值

Php 显示所选按钮值,php,html,post,get,Php,Html,Post,Get,这是一个html表单。我想打印所选按钮的值。 我尝试了一些代码,但它不起作用 HTML <form method='post' name="letter" > <input type='submit' name='A' value='A'/><br/> <input type='submit' name='B' value='B'/><br/> <input type='submit' name='G' value='G'/>

这是一个html表单。我想打印所选按钮的值。 我尝试了一些代码,但它不起作用

HTML

<form method='post' name="letter" >
<input type='submit' name='A' value='A'/><br/>
<input type='submit' name='B' value='B'/><br/>
<input type='submit' name='G' value='G'/><br/>
</form>
<form method='post' name="letter" >
<input type='submit' name='getValue' value='A'/><br/>
<input type='submit' name='getValue' value='B'/><br/>
<input type='submit' name='getValue' value='G'/><br/>
</form>




PHP

<?php
$selected_val='';
if(isset($_GET['letter'])){
$selected_val = $_GET['letter'];
}
echo $selected_val;
?>
<?php
$selected_val='';
if(isset($_POST['getValue'])){
$selected_val = $_POST['getValue'];
}
echo $selected_val;
?>

为所有提交按钮设置相同的名称

HTML

<form method='post' name="letter" >
<input type='submit' name='A' value='A'/><br/>
<input type='submit' name='B' value='B'/><br/>
<input type='submit' name='G' value='G'/><br/>
</form>
<form method='post' name="letter" >
<input type='submit' name='getValue' value='A'/><br/>
<input type='submit' name='getValue' value='B'/><br/>
<input type='submit' name='getValue' value='G'/><br/>
</form>




获取具有按钮名称的值

PHP

<?php
$selected_val='';
if(isset($_GET['letter'])){
$selected_val = $_GET['letter'];
}
echo $selected_val;
?>
<?php
$selected_val='';
if(isset($_POST['getValue'])){
$selected_val = $_POST['getValue'];
}
echo $selected_val;
?>