0

So, I'm trying to get a login page to work but I have a few errors. Here's a breakdown of what's happening and what's not working.

  1. The page loads properly, and everything can be seen.
  2. If I input a correct username & password combo, I know it's been received as the page simply turns blank. However, the echo statements don't print.

    echo "You have been logged in as ".$firstName." ".$lastName.", (".$user.").";   
    echo "<a href = 'GroceryOrder.php'>Confirm</a>";
    
  3. When something incorrect is inputted into the user and password fields, instead of printing the error message, the page just reloads, with no new message printed.
  4. My button to create an account works.

Any help would be much appreciated! Here's the body of my code so far (and my database is set up properly, I've already checked). Also, I called session_start(); at the top of the doc before my head info.

MandyLB
  • 307
  • 1
  • 4
  • 18
  • 2
    Are you having that whole HTML inside a single string? `:o` – Praveen Kumar Purushothaman Jun 30 '16 at 09:53
  • It's because I want that called just as is when the page is opened, and recalled if certain things are inputted incorrectly. Is there a better way to set it up then? *Also there's a php variable that I want to change depending what is inputted. – MandyLB Jun 30 '16 at 09:57
  • Better to use `include("page.inc")` or something. The main reason is, it's difficult for the developer to change anything inside that. Agree? – Praveen Kumar Purushothaman Jun 30 '16 at 09:58
  • First thing I see when opening a file with this code: Notice: Undefined index: loginBtn in root\index.php on line 41 – Matheno Jun 30 '16 at 10:00
  • Do you have any suggestions on how to better format it? As previously mentioned, it's just because I want to continue calling and re-printing that html code, with edited error messages. – MandyLB Jun 30 '16 at 10:09

2 Answers2

0

Try to replace if ($_POST['loginBtn']){ with if (isset($_POST['loginBtn'])){

This will check if "submitBtn" has ANY value set, instead of checking if the value submitted with the name "submitBtn" is just "true"
(wich it doesn't seem to be in your case)

Minzkraut
  • 2,149
  • 25
  • 31
  • This helped get rid of an error saying loginBtn was undefined, but didn't help to get things working correctly overall. – MandyLB Jun 30 '16 at 10:03
  • You should keep the HTML out of the PHP and vice versa, for better readability. It is somewhat hard to spot any errors – Minzkraut Jun 30 '16 at 10:07
0

The problem here is how you are checking the POST. Use:

if (count($_POST)) // This checks if there's anything being posted to the page.
Praveen Kumar Purushothaman
  • 164,888
  • 24
  • 203
  • 252