lundi 28 octobre 2019

how do I resolve "unexpected else parser error:syntax error"

I know this has been posted about ten thousand times, but I have checked and checked again, and even rewrote the whole document, but I can't fix it, it seems.

So please don't mind that it has been posted before.

Onto the Problem:

I am trying to write a PHP/HTML Login Script, the "signup.php" has the form data and they are then transfered onto the database and error handler "signup.inc.php".

Whenever the form is entered the browser delivers the following error:

Parse error: syntax error, unexpected 'else' (T_ELSE) in C:\xampp\htdocs\loginsystem\includes\signup.inc.php on line 64

Here is the code from signup.inc.php

    <?php
if (isset($_POST['signup-submit'])) {

  require 'dbh.inc.php';



  $Username = $_POST['uidUsers'];
  $Email = $_POST['emailUsers'];
  $password = $_POST['pwdUsers'];
  $passwordrepeat = $_POST['pwd-repeat'];
  $vorname = $_POST['vornameUsers'];
  $nachname = $_POST['nameUsers'];
  $strasse = $_POST['streetUsers'];
  $rufnummer = $_POST['phoneUsers'];
  $hausnummer = $_POST['streetnoUsers'];
  $plz = $_POST['plzUsers'];
  $ort = $_POST['ortUsers'];



    if (empty($Username)
    || empty($Email)
    || empty($password)
    || empty($passwordrepeat)
    || empty($vorname)
    || empty($nachname)
    || empty($strasse)
    || empty($rufnummer)
    || empty($hausnummer)
    || empty($plz)
    || empty($ort))
    {
      header("Location: ../signup.php?error=emptyfields&uidUsers=".$Username."&mail=".$Email);
      exit();

    } elseif (!filter_var($Email, FILTER_VALIDATE_EMAIL) && !preg_match("/^[a-zA-Z0-9]*$/",$Username)) {
      header("Location: ../signup.php?error=invalidmailuid");
      exit();

    } elseif (!filter_var($Email, FILTER_VALIDATE_EMAIL)) {
      header("Location: ../signup.php?error=invalidmail&uidUsers=".$Username);
      exit();

    } elseif (!preg_match("/^[a-zA-Z0-9]*$/",$Username)) {
      header("Location: ../signup.php?error=invaliduid&mail=".$Email);
      exit();

    } elseif ($password !== $passwordrepeat) {
      header("Location: ../signup.php?error=passwordcheck&uidUsers=".$Username."&mail=".$Email);
      exit();

    } else {

      $sql = "SELECT uidUsers FROM users WHERE uidUsers=?";
      $stmt = mysqli_stmt_init($conn);
          if (!mysqli_stmt_prepare($stmt, $sql)) {
              header("Location: ../signup.php?error=sqlerror");
                exit();
                }

    } else { 
            mysqli_stmt_bind_param($stmt, "s", $Username);
            mysqli_stmt_execute($stmt);
            mysqli_stmt_store_result($stmt);
            $resultcheck = mysqli_stmt_num_rows($stmt);
              if ($resultcheck > 0) {
                header("Location: ../signup.php?error=usertaken&mail=".$Email);
                exit();
            }

    } else {
                $sql = "INSERT INTO users (uidUsers, nameUsers, vornameUsers, pwdUsers, emailUsers, phoneUsers, streetUsers, streetnoUsers, plzUsers, ortUsers) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
                $stmt = mysqli_stmt_init($conn);
                if (!mysqli_stmt_prepare($stmt, $sql)) {
                  header("Location: ../signup.php?error=sqlerror");
                  exit();
                }
    } else {
                $hashedPwd = password_hash($password, PASSWORD_DEFAULT); 
                  mysqli_stmt_bind_param($stmt, "ssssssssss", $Username, $nachname, $vorname, $hashedPwd, $Email, $rufnummer, $strasse, $hausnummer, $plz, $ort);  
                  mysqli_stmt_execute($stmt);
                  header("Location: ../signup.php?signup=success");
                  exit();
                  }


      mysqli_stmt_close($stmt);
      mysqli_close($conn);


    }

  else  {
          header("Location: ../signup.php");
          exit();
        }

If you have any questions or if I haven't explained something correctly, do ask me, please

Thank you for your attention, and your help

Aucun commentaire:

Enregistrer un commentaire