php - 从php中的另一个页面获取变量
问题描述
我想将变量用户名显示到另一个页面中。这些是我使用的代码。这是插入用户名的第一页。
<?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 中的用户名我该如何解决?
解决方案
应该可以改
<form action="" method="post">
至
<form action="final.php" method="post">
推荐阅读
- java - 无法将 tomcat-native 库与 Tomcat 9 链接
- c - for 循环没有考虑执行的最后一个循环
- asp.net-core - 在我的业务中使用 .net Core Identity
- python - 如何提取仅来自本地人的推文?
- solr - 如何在 Solr 中高效存储重复数据而不影响性能
- c# - if 语句未正确退出 C# 和 Unity
- matlab - 增强matlab中二次方程的鲁棒性
- bash - Bash stderr 重定向在某些情况下不起作用
- reactjs - 31.0.0 不是有效的 SDK 版本。选项是 32.0.0 UNVERSIONED
- javascript - 我们如何更改 v2 div 中存在的 ap 标签的值?