你好,我试图得到一个选定的值,并选择它时做的东西。也试图打印文本框(打印只是临时)php获取选择选项和文本输入
<form name="recAdd" method="GET" action="add.php">
<select name="rec">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select><br>
<input type="text" name="name" />
<input type="submit" value="Submit" />
</form>
PHP(add.php):
switch($_POST['rec']){
case '1':
$rec1 = "rec1.txt";
$fh = fopen($rec1, 'a') or die("can't open file");
$romString = $_GET['name'];
fwrite($fh, $romString);
fclose($fh);
print()
break;
case '2':
// do Something
break;
case '3':
// do Something
break;
default:
print("Not working ;(");
}
没有尽一切看的文本框,下拉我用这个和它的工作(只是看是否写入文件被罚款等)
$recAll = "recAll.txt";
$fh = fopen($recAll, 'a') or die("can't open file");
$stringData = "New Stuff 1\n";
fwrite($fh, $stringData);
$stringData = "New Stuff 2\n";
fwrite($fh, $stringData);
fclose($fh);
Stackoverflow使它只显示123. - 谢谢Theraot编辑它 – user1043816
你是在混合GET和POST的目的?而...你又有什么问题了?如果你不确定使用了什么请求方法,你可以试试$ _SERVER ['REQUEST_METHOD']; – Theraot
@Theraot你应该发布它作为答案。 –