我想将变量用户名显示到另一个页面。 这些是我用过的代码。 这是插入用户名的第一页。
<?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">
关于php - 从php中的另一个页面获取变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50379943/