首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >PHP表单设计帮助

PHP表单设计帮助
EN

Stack Overflow用户
提问于 2011-09-22 01:38:55
回答 1查看 394关注 0票数 1

可能重复:

Robust, Mature HTML Parser for PHP

Help coding an HTML Form

这是我心目中的一个设计模型- http://i.imgur.com/ujiLb.jpg

从每组选项中,只有一个必须被选中,根据复选框的组合,“提交”按钮指向网页。

这两个特性将是

价格(请选择一个)

1-99 100-249 250-499

制造商(请选择一个)

A、B、C

提交按钮

我所能理解的绝对错误的编码是:

代码语言:javascript
运行
复制
//search page
...
<form action='search.php' method='post'>
<input type=radio name=product value='a'>A?</input>
<input type=radio name=product value='b'>B?</input>
<input type=radio name=product value='c'>C?</input>
<br>
<input type=radio name=price value='5'>5-10?</input>
<input type=radio name=price value='10'>11-15?</input>
<input type=radio name=price value='other'>15+?</input>
... </form>

在search.php里,就像.

代码语言:javascript
运行
复制
<?php
$product = $_POST("product");
$price = $_POST("price");
...
if (($product == "A") && ($price == "5")) {
 Location("a-5-10.html"); // Products matching A, price 5-10 etc
elseif (($product == "B") && ($price == "5")) {
 Location("b-5-10.html"); //Products matching b, price 5-10 etc
....
endif
?>

根据OP的注释编辑,请求不会被重定向到"b-5-10.html“或"a-5-10.html”等。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-09-22 01:59:35

$_POST是一个数组,而不是一个函数,您需要$_POST['product'];

代码语言:javascript
运行
复制
$product = $_POST["product"]; //note [ and ] instead of ( and )
$price = $_POST["price"];

此外,Location不是我所知道的函数,@erisco指出,您需要使用header

代码语言:javascript
运行
复制
if (($product == "A") && ($price == "5")) {
  header("Location: a-5-10.html"); // Products matching A, price 5-10 etc
} //also note the closing brace
elseif (($product == "B") && ($price == "5")) 
{ 
  header("Location: b-5-10.html"); //Products matching b, price 5-10 etc
} //again, closing brace, not "endif"
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/7508609

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档