【问题标题】:PHP sending variable to other pagePHP将变量发送到其他页面
【发布时间】:2014-05-24 18:10:04
【问题描述】:

我有一个表单,在 isset 函数数据被插入到 db 时,它也从 db 返回一个名为 id 的变量。我想将此变量发布到下一页。 这是代码;

if (isset($_POST['preview'])){


echo $user = $_SESSION['ue'];
echo $title=$_POST['title'];
echo $dis=$_POST['dis'];
echo $a=$_POST['a'];
echo $b=$_POST['b'];
echo $c=$_POST['c'];
echo $d=$_POST['d'];
echo $timespan=$_POST['timespan'];

$sql="INSERT INTO survey (user, title, description, opta, optb,optc,optd,time) VALUES ('$user','$title', '$dis', '$a' , '$b', '$c', '$d','timespan')";
if (mysqli_query($con,$sql))
 {
  echo "Success";
 }
 else
  {
  echo "Error: " . mysql_error();
  }
  $id = mysqli_insert_id($con); //variable to send to next page


mysqli_close($con); 

}
?>

提前致谢:)

【问题讨论】:

  • 这取决于:你如何进入下一页?如果您使用的是header(),那么您可以将 id 作为获取参数(查询字符串)附加。
  • 不使用 header() 只使用 isset()。实际上下一页不是,界面它只是一个php脚本。
  • 保存在会话中然后清除

标签: php mysql post get


【解决方案1】:

您可以使用 url 中的 GET 属性发送它而不是下一页:

header("Location: http://mydomain.com/myOtherPage.php?id=".$id);

在 myOtherPage 你可以使用:

if(isset($_GET['id']))
{

$idFromPreviousPage=$_GET['id'];

} 

【讨论】:

    猜你喜欢
    • 2013-03-30
    • 2022-01-09
    • 1970-01-01
    • 1970-01-01
    • 2015-09-06
    • 2014-01-18
    • 1970-01-01
    • 1970-01-01
    • 2014-09-01
    相关资源
    最近更新 更多