php传值
我是php初学者,怎么实现这两个页面的传值???
1.php
<table width="208" border="1" align="center" cellpadding="0" cellspacing="0">
<form name="form1" method="post" action="2.php">
<tr>
<td width="71" align="right">玩家</td>
<td width="131"><input name="username" type="text" id="username" size="15" /></td>
</tr>
<tr>
<td align="right">成绩</td>
<td><input name="grade" type="text" id="grade" size="15"/></td>
</tr>
<tr>
<td align="right"> </td>
<td><input type="submit" name="Submit" value="提交"/></td>
</tr>
</form></table>
2.php
<?php
$_POST[username]=$username; //获取提交的变量值
$_POST[grade]=$grade;
if($Submit == "提交"){
echo "玩家" . $_POST[username] . "<br>";
echo "成绩" . $_POST[grade] . "<br>";
if($grade>70)
echo "你赢了!";
if($grade<90){echo "你输了!";}
if($grade>88){echo "恭喜你!";}
else{
echo "下次努力!";
}
if($grade<60)
echo "你太差了!";
elseif($grade>70 && $grade<88)
echo "水平一般!";
elseif($grade>88 && $grade<99)
echo "技术很好啊!";
else
echo "技术很好!";
}
?>
[解决办法]
你弄反掉了,不是
$_POST[username]=$username; //获取提交的变量值
$_POST[grade]=$grade;
而是
$username = $_POST[username];
$grade = $_POST[grade];
$_POST是个特殊数组,提交的数据都放在里面,不要对它进行赋值
[解决办法]