Lewis Lewis - 17 days ago 10
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:

if($_SERVER['REQUEST_METHOD'] == 'POST'){


Still no luck.

PHP:

//error_reporting(E_ALL);
//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."'");
if($usernameCheck->num_rows){
echo "Username exists";
} else {
echo "Non existant";
}
}


HTML:

<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>
<div class="login_form_input">
<input type="password" class="login_input_style" placeholder="Password" id="pw" name="pw" maxlength="56">
</div>
<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>
</div>
</div>
</form>

Answer

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.