我想回显数组“名称”的一部分,然后在它旁边有一个提交按钮,该按钮重定向到一个新页面,该页面回显数组的其余部分,例如。地址,电话号码等。但是信息在重定向时丢失了。有什么办法解决这个问题。这段代码应该可以解释我的意思。
第 1 页:
<?php
$info = mysql_query ("SELECT * FROM table WHERE name= 'something'");
$info = mysql_fetch_assoc($info));
?>
<html>
<form action='page2.php' method='POST'>
<?php echo $info['name']; ?>
<input type='submit' value='see other details'>
</form>
</html>
第 2 页:
<?php
echo $info['address'].$info['address'].$info['address'];
?>
最佳答案
the information gets lost when redirected. is there some way around this
是的,使用 PHP session 。将您的数组存储为 $_SESSION['info']
,它将在下一页上可用。不要忘记在两个页面上 session_start()
。
第 1 页:
<?php
session_start();
$info = mysql_query ("SELECT * FROM table WHERE name= 'something'");
$info = mysql_fetch_assoc($info));
$_SESSION['info'] = $info;
?>
第 2 页:
<?php
session_start();
$info = $_SESSION['info'];
echo $info['address'].$info['address'].$info['address'];
?>
关于php - 将 mysql 查询数据存储为变量并通过表单在另一个页面上回显信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13883000/