Lewis Lewis - 10 months ago 53
HTML Question

Possible stupid error! IF statement not running?

A little context, the registration part works fine, however I want to now add a login system. I want to test to see if the username exists but this isn't working.

Can anyone spot the error here?

Feel free to check it on a server over here - it's a WIP so there's still lots to do. The username "Lewis" is currently entered into the database for testing purposes.
As you can see, after the form has been filled etc. none of the echo statements run, in fact, even if an echo is put directly below the first 'IF' statement, it still doesn't print, so what is the problem? I've also tried changing the IF to:


Still no luck.


//ini_set('display_errors', TRUE);

require 'vdb_includes/db.php';
require 'functions.php';

if(!empty($_POST['username']) && !empty($_POST['pw'])){

$verifyUsername = $_POST['username'];
$verifyPassword = $_POST['pw'];

$usernameCheck = mysqli_query($con, "SELECT * FROM users WHERE username='".$verifyUsername."'");
echo "Username exists";
} else {
echo "Non existant";


<form id="login_form" action="http://valhq.com/login" method="POST">
<div class="login_form_content">
<div class="login_form_input">
<input type="text" class="login_input_style" placeholder="Username" id="username" name="username" maxlength="20">
<div class="login_form_input">
<input type="password" class="login_input_style" placeholder="Password" id="pw" name="pw" maxlength="56">
<input type="submit" id="submit" name="submit" class="login_submit" value="Login">
<div class="login_notMember">
<a href="http://valhq.com/register">Don't have an account? Sign up.</a>

Answer Source

You have a 301 redirect to add a slash at the end of your url when it's missing. You haven't got a slash at the end of your form action and because of that the form post gets redirected to the url with the slash. Solution: add a slash at the end of the form action and it will work.