Hi all, I am working on the following code and I am having a problem with defined variables. On the output on the Submitted and Username Inputs as being undefined. I have added $username = (isset($_POST['Username'])) ? $_POST['Username'] : ""; at the start of the function but not suppressed.

Thanks for your help




    include_once ("includes/settings.php");
    //include_once ("includes/optional.php");


    $Errors = "";
    $_SESSION['LoggedIn'] = false;
    $_SESSION['UserID'] = "";
    $_SESSION['UserAdmin'] = false;

      if ($_POST['Submitted'] == "true") {

        // process submitted data
        $userSQL = $Database->Execute("SELECT UserID, UserFullname, UserEmail, UserLastPassword FROM Users WHERE UserName = '" . mysql_real_escape_string($Text->ValidSQLString($_POST['Username'])) . "' AND UserPassword = '" . md5($_POST['Password']) . "' AND UserActive = 1 AND UserListingOnly = 0 AND UserID NOT IN (61)");
        $UserCount = $Database->RecordCount($userSQL);

        if ($UserCount == 1) {
                // user found
                $rowUser = $Database->Records($userSQL);

        }//end if
    }//end if

Login function

      function LoginForm(){
      $username = (isset($_POST['Username'])) ? $_POST['Username'] : "";
      $password = (isset($_POST['Password'])) ? $_POST['Password'] : "";
            <form action="<?= $Settings['WS-HTTPpath']; ?>" autocomplete="off" id="Login" method="post" name="Login">
                <input id="Submitted" name="Submitted" type="hidden" value="true" />
                <label class="label-rounded" for="Username">Username</label>
                <input class="input-text-rounded" id="Username" name="Username" type="text" value="<?= $_GET['Username']; ?>" /><br />
                <label class="label-rounded" for="Password">Password</label>
                <input class="input-text-rounded" id="Password" name="Password" type="password" />
                <div class="centre mbottom">
                 <input class="button input-button-rounded shadow-small" id="LoginButton" name="LoginButton" type="submit" value="Login" />
    <?php    } ?>

Line 47 uses GET without any isset.

Line 47, why are you using $_GET['Username'] instead of just $username?

Not related to the solution, but you can probably get rid of line 42.

Hi EvolutionFallen, The reasoning behind using line 42 was to check if it had a value? and that it was not trying to validate the data input when it was already empty, so just for my learning because the I compare the input variable to the DB value, this will reject it due to the fact it is empty.

Hi Pritaeas thank you for your reply. I may need to change the line to $username, but it I used it where would I put the isset check and will this correct the submitted error also.

Thank you both for your assistance


Hi Pritaeas, I have worked out the isset with value="<?= (isset($_GET['Username'])); ?>".

I am still getting th error with Undefined index: Submitted in C:\wamp\www\oop_settings\index.php on line 19.

What am I missing ?

Any help would be appreciated



There's no isset check on $_POST['Submitted']

B.t.w. This

value="<?= (isset($_GET['Username'])); ?>"

outputs nothing, it should be:

value="<?= (isset($_GET['Username']) ? $_GET['Username'] : ''); ?>"

Hi Pritaeas, Thanks for your reply.

Not sure what the acronym B.t.w. This means, I have applied your second point and this seems to work ok.

On the submitted error if ($_POST['Submitted'] == "true") {//some code } on line 19 I still get the error, I have turned errors off and looks good, but if you have a solution for this problem I would like to apply it, so i can understand the problems next time.

Thanks again for your support it's very much appreciated.


Not sure what the acronym B.t.w.

By the way

if ($_POST['Submitted'] == "true")

if (isset($_POST['Submitted']) and ($_POST['Submitted'] == 'true')) { }

Thanks for that Pritaeas (B.t.w) lol. That seems to have done the trick
Thanks again