我可以在不同的页面上使用 $_POST 2 次吗?
can I use $_POST 2 times with different page?
我们可以在不同的页面上使用 $_POST 2 次吗?
这个例子..
action.php
<form action="next.php" method="post">
<input name="test" value="test" />
<button type="submit" name="test">submit</button>
</form>
next.php
<?php
$test=$_POST['test'];
?>
<form action="next1.php" method="post">
<input name="test1" value="<?php echo $test; ?>" />
<button type="submit" name="test1">submit</button>
</form>
next1.php
<?php
echo $test2=$_POST['test1']; >> in here i didnt get test1 value . why ?
?>
您需要再次使用第二种形式发送 POST 值,例如在隐藏字段中,否则将不会发送值。
此外,您的提交按钮不应与您要从中获取内容的输入字段同名。所以更改提交按钮的名称,例如:
action.php
<form action="next.php" method="post"> <input name="test" value="test" /> <button type="submit" name="submit">submit</button> </form>
next.php
<form action="next1.php" method="post">
<input name="test1" value="<?php echo $test; ?>" />
<button type="submit" name="submit">submit</button>
</form>
在 next.php
和 action.php
中,您需要更改 输入类型 ,如
<input type="text" name="test" value="test" />
<input type="text" name="test1" value="<?php echo $test; ?>" />
在 next.php 和 action.php 中,您缺少 type attr
的 输入 标签
并且 submit
和 next.php 中的 input
具有相同的 name attributes
需要从相应的
中删除或更改值
<input type="submit" value="submit"/>
下面的代码我已经尝试过我的本地服务器并成功执行。
action.php:-
<form action="next.php" method="POST">
<input type="text" name="test"/>
<input type="submit" value="submit"/>
</form>
next.php:-
<?php
$test = $_POST['test'];
echo $test;
?>
<form action="next1.php" method="POST">
<input name="test1" value="<?php echo $test; ?>" />
<input type="submit" value="submit"/>
</form>
next1.php:-
<?php
$test2=$_POST['test1'];
echo "------".$test2;
?>
希望这会help.I认为这已达到您的要求。
如果您想在一个文件中完成,例如index.php 那么这里是代码
<?php
if(isset($_POST['test'])){
if(isset($_POST['test_text'])){
echo 'Output from NEXT: '.$_POST['test_text'];
}
}
elseif(isset($_POST['test1'])){
if(isset($_POST['test_text1'])){
echo 'Output from NEXT1: '.$_POST['test_text1'];
}
}
?>
<table style="width:100%;">
<tr >
<td style="width:50%;">
<form action="" method="post" name="next">
<input type="text" name="test_text" value="<?php echo isset($_POST['test_text']) ? $_POST['test_text']:''; ?>" />
<button type="submit" name="test">submit test1</button>
</form>
</td>
<td style="width:50%;">
<form action="" method="post" name="next1">
<input type="text1" name="test_text1" value="<?php echo isset($_POST['test_text1']) ? $_POST['test_text1']:''; ?>" />
<button type="submit" name="test1">submit test1</button>
</form>
</td>
</tr>
</table>
希望对您有所帮助。
我们可以在不同的页面上使用 $_POST 2 次吗? 这个例子..
action.php
<form action="next.php" method="post">
<input name="test" value="test" />
<button type="submit" name="test">submit</button>
</form>
next.php
<?php
$test=$_POST['test'];
?>
<form action="next1.php" method="post">
<input name="test1" value="<?php echo $test; ?>" />
<button type="submit" name="test1">submit</button>
</form>
next1.php
<?php
echo $test2=$_POST['test1']; >> in here i didnt get test1 value . why ?
?>
您需要再次使用第二种形式发送 POST 值,例如在隐藏字段中,否则将不会发送值。
此外,您的提交按钮不应与您要从中获取内容的输入字段同名。所以更改提交按钮的名称,例如:
action.php
<form action="next.php" method="post"> <input name="test" value="test" /> <button type="submit" name="submit">submit</button> </form>
next.php
<form action="next1.php" method="post">
<input name="test1" value="<?php echo $test; ?>" />
<button type="submit" name="submit">submit</button>
</form>
在 next.php
和 action.php
中,您需要更改 输入类型 ,如
<input type="text" name="test" value="test" />
<input type="text" name="test1" value="<?php echo $test; ?>" />
在 next.php 和 action.php 中,您缺少 type attr
的 输入 标签
并且 submit
和 next.php 中的 input
具有相同的 name attributes
需要从相应的
<input type="submit" value="submit"/>
下面的代码我已经尝试过我的本地服务器并成功执行。
action.php:-
<form action="next.php" method="POST">
<input type="text" name="test"/>
<input type="submit" value="submit"/>
</form>
next.php:-
<?php
$test = $_POST['test'];
echo $test;
?>
<form action="next1.php" method="POST">
<input name="test1" value="<?php echo $test; ?>" />
<input type="submit" value="submit"/>
</form>
next1.php:-
<?php
$test2=$_POST['test1'];
echo "------".$test2;
?>
希望这会help.I认为这已达到您的要求。
如果您想在一个文件中完成,例如index.php 那么这里是代码
<?php
if(isset($_POST['test'])){
if(isset($_POST['test_text'])){
echo 'Output from NEXT: '.$_POST['test_text'];
}
}
elseif(isset($_POST['test1'])){
if(isset($_POST['test_text1'])){
echo 'Output from NEXT1: '.$_POST['test_text1'];
}
}
?>
<table style="width:100%;">
<tr >
<td style="width:50%;">
<form action="" method="post" name="next">
<input type="text" name="test_text" value="<?php echo isset($_POST['test_text']) ? $_POST['test_text']:''; ?>" />
<button type="submit" name="test">submit test1</button>
</form>
</td>
<td style="width:50%;">
<form action="" method="post" name="next1">
<input type="text1" name="test_text1" value="<?php echo isset($_POST['test_text1']) ? $_POST['test_text1']:''; ?>" />
<button type="submit" name="test1">submit test1</button>
</form>
</td>
</tr>
</table>
希望对您有所帮助。