/    Sign up×
Community /Pin to ProfileBookmark

Submitting form by pressing Enter key, leaves behind the $_POST variables

Here is my simple form

“`

<form action=”login.php” method=’POST’>
<section class=”form-top”>
<img src=”assets/img/working.gif” alt=””>
</section>

<section class=”form-main” id=”form-login”>
<?php
if (isset($_POST[‘login-submit’])) {
$username = $_POST[‘inp-username’];
$password = $_POST[‘inp-password’];

echo $username;
echo $password;

$sql = “SELECT * FROM `admin_users` WHERE `Username`='”.$username.”‘ AND `Password`='”.$password.”‘”;
$result = mysqli_query($connection, $sql);
if (mysqli_num_rows($result) == 0) {
// No such user
echo ‘<label id=”error-messages” style=”text-align: center; color: red; margin: 0; font-size: 14px; margin-bottom: 15px;”> Не правильный логин или пароль</label>’;
} else {
set_username($username);
?>
<script type=”text/javascript”>
window.location = ‘dashboard.php’
</script>
<?php
exit;
}
}
?>
<label for=”inp-login”>Username:</label>
<input type=”text” id=”inp-username” placeholder=”[email protected]” name=”inp-username”>

<label for=”inp-password”>Password:</label>
<input type=”text” id=”inp-password” placeholder=”example123″ name=”inp-password”>

<label id=”error-messages” style=”text-align: center; color: red; margin: 0; font-size: 14px;”></label>

<button class=”submit-button”>
<input type=”submit” id=”login-submit” name=”login-submit” value=”Войти”>
</button>
</section>
</form>

“`

When I am pressing the button with my mouse – works just fine! But If I use TAB to navigate through inputs and then go to submit button and press Enter, then the page gets refreshed as it should, but $_POST[‘inp-username’] is null…

Thank you!

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@SempervivumJul 25.2021 — Single backticks (probably created by the button `&lt;/&gt;</C>) won't work reliably when posting code. You better use code tags: <C>your code here` or triple backticks. I edited your posting accordingly.
×

Success!

Help @weareandrei spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.25,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...