$_GET变量在其他函数中为为什么的不到值?

yyhlong 2003-05-14 09:04:04
这个测试文件:
aaa.php

<html>
<head>
<title>测试get变量</title>
</head>
<body>
<table>
<tr>
<td><a href="test.php?ids=2">测试</a></td>
</tr>
</table>
</body>

test.php
<?
$thisprog = "test.php";
if(empty($_POST['action']))
{
test_index();
exit;
}
elseif($_POST['action'] == "add")
{
test_add();
exit;
}
function test_index()
{
global $thisprog;
echo $_GET['ids'];//这里的值是2
?>
<form action="<?=$thisprog?>" method="POST">
<table>
<tr>
<td>
<input type="text" name="title" size="8">
<input type="hidden" name="action" value="add">
<input type="submit" name="submit" value="测试">
</td>
</tr>
</table>
</form>
<?
echo $_GET['ids'];//这里的值也是2
}
function test_add()
{
echo $_GET['ids'];//这里就没有值了,为什么?

echo $_POST['title'];
}
?>
为什么在test_add()函数中的不到通过点击test.php?ids=2传递过来的
$_GET['ids']的值呢?
...全文
50 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
SuanAddMiao 2003-05-14
  • 打赏
  • 举报
回复
这一句不对,提交时,没有把ids值包含进去
<form action="<?=$thisprog?>" method="POST">
改为:
<form action="<?php echo $thisprog;?>?ids=2" method="POST">
xuzuning 2003-05-14
  • 打赏
  • 举报
回复
函数test_add() 是在提交后才会执行的,此时并没有命令行变量ids
除非你这样写<form action="<?=$thisprog?>?ids=abc" method="POST">
onewaytosky 2003-05-14
  • 打赏
  • 举报
回复
只能说test_add() 函数没有得到执行
liftblood 2003-05-14
  • 打赏
  • 举报
回复
用$ids试试看

21,887

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧