如何从表单传递查询参数';php中的动作属性?
我想在PHP中将查询参数从一个页面传递到另一个页面。如何从表单传递查询参数';php中的动作属性?,php,html,Php,Html,我想在PHP中将查询参数从一个页面传递到另一个页面。 我使用表单的action属性而不是hyperlink标记重定向 <html> <head> <title>Question 1</title>. </head> <body> <form method="GET" action="Result.php?question=1"> <b>Question
我使用表单的action属性而不是hyperlink标记重定向
<html>
<head>
<title>Question 1</title>.
</head>
<body>
<form method="GET" action="Result.php?question=1">
<b>Question 1. What is the full form of PHP?<b> <br>
A)<input type="radio" name="q1" value="a">
Pre HyperText Processor<br>
B)<input type="radio" name="q1" value="b">
Post HylerText Processor<br>
C)<input type="radio" name="q1" value="c">
Personal HyperText Pages<br>
D)<input type="radio" name="q1" value="d">
HyperText Preprocessor<br>
<input type="submit" name="g" value="Go">
</form>
</body>
Result.php
<?php
$score=0;
$q=$_GET["question"];
if($q)
{
if($_GET['g']!=null)
{
switch($q)
{
case 1: $answer1='c';
if($_GET["q1"]==answer1)
++$score;
break;
default: print " try again";
}
}
}
<?php
$q=$_GET["question"];
if($q)
{
$PostedValue = $_POST['q1'];
switch($PostedValue)
{
case 'a': echo "Pre HyperText Processor";
break;
case 'b': echo "Post HylerText Processor";
break;
case 'c': echo "Personal HyperText Pages";
break;
case 'd': echo "HyperText Preprocessor";
break;
}
}
?>
$q=$_GET["question"];
...
if($_POST['g']!=null)
...
if($_POST["q1"]==$answer)
...
您不能返回$\u GET['question']
。
您将返回q1
。因此,您所做的将有一个url,如:
Result.php?q1=a&g=Go"
因此,您必须将Result.php设置为
$q=$_GET["q1"];
if($q)
{
switch($q)
{
case 'a': print "question 1";
break;
}
}
如果你想让你的url有问题,你需要这样做:
<form method="GET" action="Result.php">
<b>Question 1. What is the full form of PHP?<b> <br>
A)<input type="radio" name="question1" value="a">
Pre HyperText Processor<br>
B)<input type="radio" name="question1" value="b">
Post HylerText Processor<br>
C)<input type="radio" name="question1" value="c">
Personal HyperText Pages<br>
D)<input type="radio" name="question1" value="d">
HyperText Preprocessor<br>
<input type="submit" name="g" value="Go">
问题1。PHP的完整形式是什么
(A)
超文本前处理器
(B)
后HyleText处理器
(C)
个人超文本页面
(D)
超文本预处理器
请记住,这是一个快速修复方法,但不要使用GET。使用POST insted。
还可以使用FireBug查看如何获取或发布表单
编辑
最好使用POST,否则会覆盖您的url。
试试这个,如果你想要的话告诉我
<html>
<head>
<title>Question 1</title>.
</head>
<body>
<form method="POST" name="form" action="Result.php?question=1">
<b>Question 1. What is the full form of PHP?<b> <br>
A)<input type="radio" name="q1" value="a">
Pre HyperText Processor<br>
B)<input type="radio" name="q1" value="b">
Post HylerText Processor<br>
C)<input type="radio" name="q1" value="c">
Personal HyperText Pages<br>
D)<input type="radio" name="q1" value="d">
HyperText Preprocessor<br>
<input type="submit" name="g" value="Go">
</form>
</body>
问题1。
问题1。PHP的完整形式是什么
(A)
超文本前处理器
(B)
后HyleText处理器
(C)
个人超文本页面
(D)
超文本预处理器
Result.php
<?php
$score=0;
$q=$_GET["question"];
if($q)
{
if($_GET['g']!=null)
{
switch($q)
{
case 1: $answer1='c';
if($_GET["q1"]==answer1)
++$score;
break;
default: print " try again";
}
}
}
<?php
$q=$_GET["question"];
if($q)
{
$PostedValue = $_POST['q1'];
switch($PostedValue)
{
case 'a': echo "Pre HyperText Processor";
break;
case 'b': echo "Post HylerText Processor";
break;
case 'c': echo "Personal HyperText Pages";
break;
case 'd': echo "HyperText Preprocessor";
break;
}
}
?>
$q=$_GET["question"];
...
if($_POST['g']!=null)
...
if($_POST["q1"]==$answer)
...
或者,如果要使用方法GET,可以通过hiddin输入传递该方法:
您可以使用自己的Result.php代码
<html>
<head>
<title>Question 1</title>.
</head>
<body>
<form method="GET" name="form" action="Result.php">
<input type="hidden" name="question" value="1">
<b>Question 1. What is the full form of PHP?<b> <br>
A)<input type="radio" name="q1" value="a">
Pre HyperText Processor<br>
B)<input type="radio" name="q1" value="b">
Post HylerText Processor<br>
C)<input type="radio" name="q1" value="c">
Personal HyperText Pages<br>
D)<input type="radio" name="q1" value="d">
HyperText Preprocessor<br>
<input type="submit" name="g" value="Go">
</form>
</body>
问题1。
问题1。PHP的完整形式是什么
(A)
超文本前处理器
(B)
后HyleText处理器
(C)
个人超文本页面
(D)
超文本预处理器
您无法获得$\u GET['question']
返回。
您将返回q1
。因此,您所做的将有一个url,如:
Result.php?q1=a&g=Go"
因此,您必须将Result.php设置为
$q=$_GET["q1"];
if($q)
{
switch($q)
{
case 'a': print "question 1";
break;
}
}
如果你想让你的url有问题,你需要这样做:
<form method="GET" action="Result.php">
<b>Question 1. What is the full form of PHP?<b> <br>
A)<input type="radio" name="question1" value="a">
Pre HyperText Processor<br>
B)<input type="radio" name="question1" value="b">
Post HylerText Processor<br>
C)<input type="radio" name="question1" value="c">
Personal HyperText Pages<br>
D)<input type="radio" name="question1" value="d">
HyperText Preprocessor<br>
<input type="submit" name="g" value="Go">
问题1。PHP的完整形式是什么
(A)
超文本前处理器
(B)
后HyleText处理器
(C)
个人超文本页面
(D)
超文本预处理器
请记住,这是一个快速修复方法,但不要使用GET。使用POST insted。
还可以使用FireBug查看如何获取或发布表单
编辑
最好使用POST,否则会覆盖您的url。
试试这个,如果你想要的话告诉我
<html>
<head>
<title>Question 1</title>.
</head>
<body>
<form method="POST" name="form" action="Result.php?question=1">
<b>Question 1. What is the full form of PHP?<b> <br>
A)<input type="radio" name="q1" value="a">
Pre HyperText Processor<br>
B)<input type="radio" name="q1" value="b">
Post HylerText Processor<br>
C)<input type="radio" name="q1" value="c">
Personal HyperText Pages<br>
D)<input type="radio" name="q1" value="d">
HyperText Preprocessor<br>
<input type="submit" name="g" value="Go">
</form>
</body>
问题1。
问题1。PHP的完整形式是什么
(A)
超文本前处理器
(B)
后HyleText处理器
(C)
个人超文本页面
(D)
超文本预处理器
Result.php
<?php
$score=0;
$q=$_GET["question"];
if($q)
{
if($_GET['g']!=null)
{
switch($q)
{
case 1: $answer1='c';
if($_GET["q1"]==answer1)
++$score;
break;
default: print " try again";
}
}
}
<?php
$q=$_GET["question"];
if($q)
{
$PostedValue = $_POST['q1'];
switch($PostedValue)
{
case 'a': echo "Pre HyperText Processor";
break;
case 'b': echo "Post HylerText Processor";
break;
case 'c': echo "Personal HyperText Pages";
break;
case 'd': echo "HyperText Preprocessor";
break;
}
}
?>
$q=$_GET["question"];
...
if($_POST['g']!=null)
...
if($_POST["q1"]==$answer)
...
或者,如果要使用方法GET,可以通过hiddin输入传递该方法:
您可以使用自己的Result.php代码
<html>
<head>
<title>Question 1</title>.
</head>
<body>
<form method="GET" name="form" action="Result.php">
<input type="hidden" name="question" value="1">
<b>Question 1. What is the full form of PHP?<b> <br>
A)<input type="radio" name="q1" value="a">
Pre HyperText Processor<br>
B)<input type="radio" name="q1" value="b">
Post HylerText Processor<br>
C)<input type="radio" name="q1" value="c">
Personal HyperText Pages<br>
D)<input type="radio" name="q1" value="d">
HyperText Preprocessor<br>
<input type="submit" name="g" value="Go">
</form>
</body>
问题1。
问题1。PHP的完整形式是什么
(A)
超文本前处理器
(B)
后HyleText处理器
(C)
个人超文本页面
(D)
超文本预处理器
最后,我找到了解决这个问题的方法。
事实证明,要访问使用表单的action属性传递的值,需要使用$\u GET。至于其他值,应使用$\u POST。
像这样的-
<form method=POST" action="Result.php?question=1">
最后,我找到了解决这个问题的办法。
事实证明,要访问使用表单的action属性传递的值,需要使用$\u GET。至于其他值,应使用$\u POST。
像这样的-
<form method=POST" action="Result.php?question=1">
我们需要将表单html视为well@Steve检查编辑,我只是将其正确格式化,以便displayed@AlexAndrei啊,接得好,我在早些时候完全错过了edit@Code_maniac“不工作”
不是描述性问题-请准确描述发生了什么。此外,您还需要编辑问题以包含完整的表单html,包括提交button@Steve我已经编辑了这个问题。需要将表单html作为well@Steve检查编辑,我只是将其正确格式化,以便displayed@AlexAndrei啊,接得好,我在早些时候完全错过了edit@Code_maniac“不行“
不是描述性问题-请准确描述发生了什么。此外,您还需要编辑问题以包含完整的表单html,包括提交button@Steve我已经编辑了这个问题。q1和问题参数都需要传递到结果页面。您已经完全更改了Result.php页面中的代码。这不是我打算做的。请把问题再读一遍。为什么我无法通过表单传递URL中的参数问题(我不想使用超链接标记)?谢谢尝试。请尝试最后一个代码。这将返回如下url?question=1&q1=a&g=GOI如果方法为“get”,操作为HTTP URI,则用户代理将获取操作的值,向其追加一个“?”,然后追加表单数据集,使用“application/x-www-form-urlencoded”内容类型进行编码。也许可以对动作URL进行百分比编码,以嵌入问号和参数,然后交叉手指,希望所有浏览器都能保持该URL不变(并验证服务器是否也理解该URL)。但我决不会相信这一点。顺便说一句:对于非隐藏表单字段来说没有什么不同。对于POST,操作URL可能包含一个查询字符串。我已经编辑了问题。q1和问题参数都需要传递到结果页面。您已经完全更改了Result.php页面中的代码。这不是我打算做的。请把问题再读一遍。为什么我无法通过表单传递URL中的参数问题(我不想使用超链接标记)?谢谢尝试。请尝试最后一个代码。这将返回如下url?question=1&q1=a&g=GoIf方法为“get”,操作为HTTP URI,