Home Get a variable from another page in php
Reply: 0

Get a variable from another page in php

user1681
1#
user1681 Published in May 25, 2018, 6:52 pm

I wanted to show the variable username into another page. These are the codes I've used. This is the first page where the username is inserted.

<?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>

Then in this page I wanted to show the username that was inserted

<?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>

But it tells me Notice: Undefined index: username in C:\xampp\htdocs\quizzer\final.php on line 29 How can I solve it please?

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.322378 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO