Jump to content

Need Help


Imaginary
 Share

Recommended Posts

Parse error: syntax error, unexpected ';' in on line 7

I been looking for a while but I think I have been over looking it. I been doing this all day so. I can not find the problem.

 

 

<?php
if (isset($_POST['login'])) {
  require 'dbh.inc.php';
  $logUid = $_POST['logUid'];
  $logPwd = $_POST['logPwd'];
  if (empty($logUid) || (empty($logPwd)) {
    header("Location: ../login.php?error=emptyfields");
    exit();
  }
    else {
      $sql = "SELECT * FROM users WHERE uidUsers=?;";
      $stmt = mysqli_stmt_init($conn);
      if (!mysqli_stmt_prepare($stmt, $sql)) {
        header("Location: ../login.php?error=sqli");
        exit();
      } else {
          mysqli_stmt_bind_param($stmt, "s", $logUid);
          mysqli_stmt_execute($stmt);
          $result = mysqli_stmt_get_result($stmt);
          if ($row = mysqli_fetch_assoc($result)) {
              $pwdCheck = password_verify($logPwd, $row['pwdUsers']);
              if ($pwdCheck == false) {
                header("Location: ../login.php?error=wrong");
                exit();
              }
              else if($pwdCheck == true) {
                session_start();
                $_SESSION['username'] = $row['uidUser'];
                $_SESSION['email'] = $row['emailUsers'];
                header("Location: ../index.php?login");
                exit();
              }  else {
                  header("Location: ../login.php?error=usernotfound");
                  exit();
        }
      }
    }
  }
}
else{
  header("Location: ../login.php");
  exit();

}

 ?>
 

Link to comment
Share on other sites

actually, you have an unnecessary ( which then doesn't have a matching ), both on line #6.

as to the posted logic. you have far too much code, mainly because your form and for processing code are not on the same page and you are using the mysqli database extension. if you put the form processing code on the same page as the form, stop copying variables to other variables, store validation errors in an array, switch to the much simpler php PDO database extension, and use exceptions to handle database errors, about half of the code you have now will go away.

you also have a logic mistake later in the code. your 'usernotfound' condition is part of the password check logic (which can only be either true of false, there's no point in the final else statement), not as part of the fetch check logic. this type of mistake can be avoided by properly indenting your code and also by eliminating unnecessary code (see the above paragraph.)

Link to comment
Share on other sites

This thread is more than a year old.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.