php 从下拉列表中保存值
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4525780/
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
Saving the value from a drop-down list
提问by DogPooOnYourShoe
Here's my situation, I have 2 pages, one for selecting a value and one for editing database related things which are associated to that value.
这是我的情况,我有 2 页,一页用于选择值,另一页用于编辑与该值关联的数据库相关内容。
Right now, I have no knowledge ( and have researched a fair bit ) on how to save the value selected from the drop down list into a variable from PHP.
现在,我对如何将从下拉列表中选择的值保存到 PHP 的变量一无所知(并且已经研究了一些)。
Any ideas?
有任何想法吗?
回答by pythonFoo
HTML:
HTML:
<form action="page.php" method="get">
<select id="drop" name="drop">
<option value="Volvo">Volvo</option>
<option value="Saab">Saab</option>
<option value="Mercedes">Mercedes</option>
<option value="Audi">Audi</option>
</select>
<input type="submit" value="Submit!">
</form>
page.php:
页面.php:
<?php
echo $_GET['drop'];
?>
回答by Chris
Its two step: First html:
它的两个步骤:首先是 html:
<form action='databasethings.php' method=post>
<select name="myvalue">
<option value="value1">Value 1</option>
<option value="value2">Value 2</option>
<option value="value3">Value 3</option>
</select>
<input type=submit>
</form>
Its for sending the value to databasethings.php script.(
它用于将值发送到 databasethings.php 脚本。(
Then in databasethings.php:
然后在databasethings.php中:
$myvalue=$_POST['myvalue'];
//do something with myvalue
This will catch value1, 2 or 3 from html into $myvalue in php
这会将 html 中的 value1、2 或 3 捕获到 php 中的 $myvalue
回答by pjabang
I presume you are submitting a form to the page for editing database related things. On that page use $_REQUEST['the_name_of_the_select_box']
我假设您正在向页面提交表单以编辑与数据库相关的内容。在该页面上使用 $_REQUEST['the_name_of_the_select_box']
<select name="the_name_of_the_select_box">
the select value will be in
选择值将在
$_REQUEST['the_name_of_the_select_box'] or $_POST['the_name_of_the_select_box']
回答by Жасулан Бердибеков
might like this
可能会喜欢这个
$('element').change(function(){
$.ajax({
url:"savepage",
type:"POST",
data:({}),
dataType:"html", // json // xml
async:false,
success: function(msg){
alert(msg); // get result
}
});
});