Reputation: 9
I am writing a new PHP website, and have written a form, and the PHP code to handle the variables and the DB.
Trouble is, it won't even submit the form! Usually when you submit, if you hit F5 it will ask if you want to 'send again', it doesn't even do that. Something is clearly wrong, and I am a little rusty - but I thought I was ok with basic forms.
<?php
$username = isset($_POST['username']) ? $_POST['username'] : null;
echo "here: $username";
if(!isset($_SESSION['username'])) {
$_SESSION['username'] = $username;
} elseif (isset($_SESSION['username'])) {
$username = $_SESSION['username'];
}
?>
<form method="post" action="/signup2/" name="signuprocess">
<input type="text" name="username">
<input type="submit" value="Sign Up">
</form>
After submitting, the $username doesn't appear after "here:". What I am doing that's a bit silly??
I have tried to post the code on here, but it sees it as spam, as it is a sign up form.
What can I post to show the code, without it being seen as such?
Upvotes: 0
Views: 47
Reputation: 2011
When you "hit" F5 and the browser asks you to 'send again' is because you previously did a POST request. Otherwise, if your last request was, for example, a GET, the browser is not going to ask you anything. It will simply refresh the page.
try something like this
<?php
$username = $_POST['username'] ?? null;
echo "here: $username";
?>
<form method="post" action="" name="signuprocess">
<input type="text" name="username" value="<?php echo $username ?>">
<input type="submit" value="Sign Up">
</form>
Upvotes: 1