How to solve the "Function name must be a string" error?

-2
  

Fatal error: Uncaught Error: Function name must be a string in   C: \ xampp \ htdocs \ Proj_solos \ php \ login.php: 11 Stack trace: # 0 {main}   thrown in C: \ xampp \ htdocs \ Proj_solos \ php \ login.php on line 11

<?php include_once './conexao.php';
$erro= array();
 if (isset($_POST['login']) && strlen($_POST['login']) >0 ){
  if (!isset($_SESSION))
      session_start ();

  $_SESSION['login'] = $mysqli ->escape_string($_POST['login']);
  $_SESSION['senha'] = md5(md5($_POST['senha'])); 

  $sql_code = "SELECT senha,login FROM usuario ->' $_SESSION[login]'";
  $sql_query = $mysqli($sql_code) or die ($mysqli->erro);
  $dado= $sql_query -> fetch_assoc();
  $total = $sql_query -> num_rows;

  if($total ==0){
      $erro[] = "Este Usuario não existe.";
  }else{
      if($dado['senha'] == $_SESSION['senha']){
          $_SESSION['login'] = $dado["ID"];

      }else{
          $erro[]= "senha Incorreta!";
      } 
  }
   if (count($erro ==0 || !isset($erro))){
       echo "<script>alert('Login efetuado com Sucesso');location.href='../php/index.php';</script>";
   }
 }
?>
    
asked by anonymous 02.08.2017 / 21:14

2 answers

2

The wrong line is clearly:

$sql_query = $mysqli($sql_code) or die ($mysqli->error);
  

The error message has also been corrected, from $mysqli->erro to $mysqli->error .

Let's consider that $mysqli is the connection object with the database and it was created in the conexao.php file. If this premise is wrong, nothing in your code makes sense. If you are right, in the above line you are passing $sql_code to the object $mysqli :

$mysqli($sql_code)

This does not make sense. For you to execute a SQL command, you need to invoke the query method of this object. Assuming you are using the MySQL OOP syntax, it would look like this:

$mysqli->query($sql_code)

This would solve the current error, but would generate another, because your SQL command is wrong:

SELECT senha,login FROM usuario ->' $_SESSION[login]'

You used this arrow syntax that does not exist in SQL. Probably what you wanted to do is:

SELECT senha, login FROM usuario WHERE login = '{$_SESSION[login]}'

Notice the use of the WHERE clause, the identification of the login column, and the use of the = operator.

The last condition of the code also makes no sense:

if (count($erro ==0 || !isset($erro))) { ... }

You are passing the return from the x || y operation, which will be a boolean type, to the count function. Do you want to count the elements of a boolean? No. Probably what you wanted to do is:

if ((count($erro) == 0) || !isset($erro)) { ... }

But there is also no reason to do so. The second operand will check for the non-existence of the variable $erro , but it is defined in line 2, that is, it will always exist. Therefore, !isset($erro) will always return False , regardless of the value of $erro . To check for any error messages, just count :

if (count($error) == 0) { ... }
    
02.08.2017 / 21:34
-1

$mysqli is as variable. It should be a command, that is, without the $ (dollar sign). Only mysqli .

    
02.08.2017 / 21:18