0

i have Parse error syntax error unexpected '{' in my code do you have the solution ? I looked for this missing parenthes is but no way to get my hands on it Thanks for your help

<?php 
require_once '../src/database.php';
if (isset($_POST)) {
  if (!empty(htmlspecialchars($_POST['username']) AND !empty(htmlspecialchars($_POST['password']))) {
    $req = $db->prepare('SELECT * FROM users WHERE username = ? AND password = ?');
    $req->execute([
      'username' => $_POST['username'],
      'password' => $_POST['password']


    ]);

      $user = $req->fetchObject();
      if ($user) {
      $_SESSION['admin'] = $_POST['username']; 
      header('location.index.php');
      }else{
        $error = 'identifiants incorrect';
      }
    }
  else{
    $error = 'Veuillez remplir tous les champs';
  }
}
if(isset($error)) {
  echo '<div class="error">'. $error .'</div>';
}

 ?>

  • missing `)` in line `f ( !empty(htmlspecialchars($_POST['username'])) AND !empty(htmlspecialchars($_POST['password']))) {` after `$_POST['username']` – Devsi Odedra Dec 21 '19 at 11:46

1 Answers1

1

You forgot close ) for htmlspecialchars()

If you are using some editor then you will know better where is the error.

if (isset($_POST)) {
  if ( !empty(htmlspecialchars($_POST['username'])) AND !empty(htmlspecialchars($_POST['password']))) {
    $req = $db->prepare('SELECT * FROM users WHERE username = ? AND password = ?');
    $req->execute([
      'username' => $_POST['username'],
      'password' => $_POST['password']


    ]);

      $user = $req->fetchObject();
      if ($user) {
      $_SESSION['admin'] = $_POST['username']; 
      header('location.index.php');
      }else{
        $error = 'identifiants incorrect';
      }
    }
  else{
    $error = 'Veuillez remplir tous les champs';
  }
}
if(isset($error)) {
  echo '<div class="error">'. $error .'</div>';
}
Devsi Odedra
  • 5,244
  • 1
  • 23
  • 37
  • Please don't answer typo questions. Comment and vote to close instead. They are rarely useful for other people. – Dharman Dec 21 '19 at 15:09