首页 > 解决方案 > 从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 中的用户名我该如何解决?

标签: phphtmlmysqlpostlogin

解决方案


应该可以改

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

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

推荐阅读