DTYlan DTYlan - 2 months ago 18
PHP Question

Isset still not doing its job

I've seen this issue all over stack overflow but none of the methods helped.

Form:

<form action="login.php" method="POST">
<input name="username" type="text" placeholder="User Name">
<input name="rawpassword" type="password" placeholder="Password">
<input value="Login" type="submit">
</form>


Login.php:

// Gets user entered details from form.
if (isset($_POST['username'])) {
$username=$_POST['username'];
} else {
$username=null;
}
if (isset($_POST['rawpassword'])) {
$rawpassword=$_POST['rawpassword'];
} else {
$rawpassword=null;
}

// Hashes password through SHA-1.
$password = sha1($rawpassword);

echo "$username";
echo "$rawpassword";
echo "$password";


My problem is that the

if (isset($_POST['']))


is coming back as false and will make both variables null and echos null (nothing). But if I was to do this:

if (!isset($_POST['']))


It returns the undefined index error that everyone gets.

Help will be much appricated.

Answer

I have fixed the issue that I was having, obviously I didn't do enough research to find out that the problem was that JQuerymobile (should have mentioned that I was using JQuerymobile) has it's own special ways of requesting pages.

All I needed to do was add data-ajax="false" into the <form> tag, now everything works how I wanted it to work.

Thank you everyone for your suggestions and help.