【问题标题】:Get a variable from another page in php从php中的另一个页面获取变量
【发布时间】:2018-10-27 01:01:57
【问题描述】:

我想将变量用户名显示到另一个页面中。 这些是我使用的代码。 这是插入用户名的第一页。

<?php
include('login.php'); // Includes Login Script
if(isset($_SESSION['login_user'])){
}
?> 

<html>
<head>
<title>Login</title>
</head>
<body>
<div id="login" align="center">
<h2>Welcome!</h2>
<form action="" method="post">
<label>Username :</label>
<input id="name" name="username" placeholder="username" type="text"><br>
<label>Password :</label>
<input id="password" name="password" placeholder="**********" type="password"><br><br>
<input name="submit" type="submit" value=" Login ">
<span><?php echo $error; ?></span>
</form>
</div>
</body>
</html>

然后在这个页面中我想显示插入的用户名

<?php include 'database.php'; ?>
<?php session_start(); ?>
<?php
function visualizza($file) {
$f = fopen($file, "r"); // apro il file in lettura
return fread($f, filesize($file));
fclose($f);
}
?>
<html>
<main>
<div class="container">
<h2> Quiz Completato!</h2>
<p> Congratulations <?php 
$username = $_POST['username']; 
echo $username;
?>

! You completed the test</p>
<p>Final Score:<?php echo $_SESSION['score']; ?> </p>
</div>
</main>

但它告诉我注意:未定义索引:第 29 行 C:\xampp\htdocs\quizzer\final.php 中的用户名 请问怎么解决?

【问题讨论】:

  • 如果第二部分在不同的文件中,您需要发布到该文件:action="final.php"。如果您想在发布数据之外引用该值,则可以将其存储在会话变量或数据库中。
  • 如果您的表单没有发布到第二页,您目前如何进入第二页??

标签: php html mysql post login


【解决方案1】:

应该可以随便改

<form action="" method="post">

<form action="final.php" method="post">

【讨论】:

    【解决方案2】:

    必须在向浏览器输出任何内容之前调用 session_start() 函数,并且您需要在需要访问会话数据的每个页面上调用此函数。

    http://php.net/manual/en/function.session-start.php

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-02-13
      • 1970-01-01
      • 2014-12-20
      • 2017-05-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多