How to resolve mysql_query error?

Asked

Viewed 209 times

1

I installed a login and registration system in a hosting, adjusted the database and connected to the system, including created a user to test the login. However when I log in it presents 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 follows below:

<?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;
		}
	
	}

?>

1 answer

1

The mysqli_query function requires 2 parameters:

  1. Connection
  2. Query to be executed.

Here is 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.

  • I made the changes and gives the same mistake!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.