html 选择不起作用
你好 我绝对被困在这里,我是一名 PHP 程序员,我认为我的 HTML 非常出色,但由于某种原因我被困在这个问题上:
我有一个表单,它有两个选择选项:
<select name="pays">
<option value ="ireland">Ireland</option>
<option value ="us">US</option>
</select>
<br>
<select name="carrier">
<option value="ireland">Irish Network</option>
<option disabled="disabled"><b>US<b></option>
<option value="verizon">Verizon</option>
<option value="sprint">Sprint</option>
<option value="att">AT&T</option>
<option value="cellularone">Cellular One</option>
<option value="nextel">Nextel</option>
</select>
我的 PHP 文件是这样的:
$country= $_POST['pays'];
$carrier= $_POST['carrier'];
。 ...
$sql="INSERT INTO members (cname, cnumber, country, carrier)
VALUES ('$name', '$number', '$country', '$carrier')";
奇怪的是,值 $name 和 $number 工作正常(它们也是表单中的输入字段),但两个选择选项为空。我已经重复了 $country 和 $Carrier,但它们是空白的,让我认为表格有问题。
有什么想法吗?
PS 没有出现错误
P.PS 如果你不会说法语,则支付=法语国家
谢谢 尼尔
Hi
I am absolutely stuck here, i'm a PHP programmer and i would consider my HTML to be excellent but for some reason i'm stuck on this:
I have a form and it has two select options :
<select name="pays">
<option value ="ireland">Ireland</option>
<option value ="us">US</option>
</select>
<br>
<select name="carrier">
<option value="ireland">Irish Network</option>
<option disabled="disabled"><b>US<b></option>
<option value="verizon">Verizon</option>
<option value="sprint">Sprint</option>
<option value="att">AT&T</option>
<option value="cellularone">Cellular One</option>
<option value="nextel">Nextel</option>
</select>
My PHP file is this:
$country= $_POST['pays'];
$carrier= $_POST['carrier'];
....
$sql="INSERT INTO members (cname, cnumber, country, carrier)
VALUES ('$name', '$number', '$country', '$carrier')";
The strange thing is that the values $name and $number work fine (they are input fields in the form aswell) but the two select options are empty. I've echoed out the $country and $carrier but they're blank, making me think there is a problem with the form.
Any ideas??
P.S no errors come up
P.P.S if you don't speak french, pays=country in french
Thanks
Niall
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
我想到两件事, print_r($_POST) 并查看值是否在 post 中。
标签内的选择框是否表明显而易见但可能是问题?
Two things come to mind, print_r($_POST) and see if the values are in post.
Are the select boxes inside the tag, stating the obvious but could be the issue?
表格看起来不错。您是否对 $country 和 $carrier 变量执行任何验证?如果您(例如)在连接到数据库之前运行 mysql_real_escape ,那么这可能会导致您描述的问题,其中变量为空。
The form looks OK. Are you performing any validation on the $country and $carrier variables? If you are (for example) running mysql_real_escape before connecting to the database then that can cause the problem you describe, where the variables are blank.
无效..应该是
is not valid.. should be
试试这个:
这是因为当您执行包含单引号的 SQL 查询时,它不会计算变量,而是直接使用单引号内的值。
Try this:
That's because when you exectue an SQL query with single quotes inside, it will not evaluate the variable, it will literally use the value inside the single quotes.
您使用了正确的方法(帖子)吗?如果您不指定,将使用
$_GET
。另外,要在一个表单帖子中同时获取“付款”和“承运人”,它们应该位于相同的Did you use the right method (post)? If you don't specify
$_GET
will be used. Also to get both "pays" and "carrier" in one form-post they should both be in the same<form>
see below example code:编辑评论:a) 我意识到这离主题太远了,b) 我的代码包含字段集的 CSS。我确实为转移注意力而道歉。 ianm
我在 www.toursbw.net 上有一个 PHP CSS 和 HTML 应用程序。使用演示选项可以访问完整系统。
当我使用三星 Android 智能手机运行此程序时,我的选择框/字段将第一行显示为空白,但是当触摸选择向下箭头时,选择选项将以与键盘相同的方式显示,并且一切正常。它需要由向下箭头触发。
选择书:
这是生成选择框/字段的代码。
($debug 代码在外部设置为 ON,在 Smartphoe 上运行时没有显示任何异常。)
希望这有一些用处,ianm
EDit Comment : a) I realsed that this is way off topic and b) my code includes CSS for the fieldset. I do apologise for the red herring. ianm
I have a PHP CSS, and HTML application online at www.toursbw.net . Using the DEMO selection gains access to the FULL SYSTEM.
When I run this using my Samsung Android Smartphone my selection boxes/fields display the first line as blank BUT when the select downarrow is touched the selection options are displayed in the same way as the keyboard and all works fine. It needs to be triggered by the down arrow.
select_book :
This is the code that produces the selection box / field.
(The $debug code is set ON externally and showed no abnormalities when run on the Smartphoe.)
Hope this is of some use, ianm
您可以使用 $_POST['name'] 从 post 方法获取值。
希望对你有帮助!!!
You can use $_POST['name'] to get value from post method.
Hope it helps you!!!