So the guest has to type their name on the homepage, and when they go to the next page it should say something like "Welcome John".
I'm trying to echo "Welcome Guest" on the other pages, but I keep receiving errors and no outcome. I've tried different ways still nothing.
Below is the last PHP code I've been trying.
<form action="homepage.php" method="post">
Name:<input type="text" name="name" placeholder="Your Name"></input><br/>
<input type="submit" style="visibility: hidden;" />
</form>
<?php
if(isset($_POST["name"]))
{echo "Welcome: ". $_POST['name']. "<br />";}
?>
You should use a session in order to remember the guests name, especially if you want to say "welcome guest" on different pages. $_POST works as a single request, so once the user refreshes the page, $_POST will be reset. This is the very basic of how it should work...
<?php
session_start();
if(isset($_POST['name']){
$_SESSION['name'] = $_POST['name'];
header("Location: homepage.php");
}
if(isset($_SESSION["name"])){
echo "Welcome: ". $_SESSION['name']. "<br />";
}else{
?>
<form action="homepage.php" method="post">
Name:<input type="text" name="name" placeholder="Your Name"></input><br/>
<input type="submit" style="visibility: hidden;" />
</form>
<?php
}
?>