How to solve mysql_query error? [duplicate]

1

I installed a login and registration system in a hosting, I adjusted the database and connected with the system, I even created a user to test the login. However when I log in he has these errors:

Warning: mysqli_query() expects at least 2 parameters, 1 given in /srv/disk5/2615118/www/ge2018.atspace.eu/classes/Login.class.php on line 4

Warning: mysql_num_rows() expects parameter 1 to be resource, null given in /srv/disk5/2615118/www/ge2018.atspace.eu/classes/Login.class.php on line 5

The error code below follows:

<?php
	class Login{
		public function logar($email, $senha){
			$buscar=mysqli_query("SELECT * FROM usuarios WHERE email='$email' AND senha='$senha' LIMIT 1");
			if(mysql_num_rows($buscar) == 1){
				$dados=mysql_fetch_array($buscar);
				if($dados["status"] == 1){
					$_SESSION["email"]=$dados["email"];
					$_SESSION["senha"]=$dados["senha"];
					$_SESSION["nivel"]=$dados["nivel"];
					setcookie("logado",1);
					$log=1;
				}else{
					$flash="Aguarde a nossa aprovação!";
				}
			}
				if(isset($log)){
					$flash="Você foi logado com sucesso";
				}else{
					if(empty($flash)){
					$flash="Ops! Digite seu e-mail e sua senha corretamente!";
					}
				}
				echo $flash;
		}
	
	}

?>
    
asked by anonymous 09.02.2018 / 07:17

1 answer

1

The mysqli_query function requires 2 parameters:

  • Connection
  • Query to be executed.
  • Here's an example:

    <?php
    $con=mysqli_connect("localhost","usuario","senha","bancodedados");
    // verifica conexão
    if (mysqli_connect_errno())
      {
      echo "Falha ao conectar com MySQL: " . mysqli_connect_error();
      }
    
    // roda a query
    mysqli_query($con,"WHERE email='$email' AND senha='$senha' LIMIT 1");
    mysqli_close($con);
    ?>
    

    Note that before the query, we also pass the connection to the database.

        
    09.02.2018 / 08:19