Warning: mysqli_query() expects at least 2 Parameters, 1 Given in C: wamp www Trabalho odesi proceslogin.php on line 22

Asked

Viewed 922 times

-4

<?php

// Busca as variaveis $login e $senha 

$login=$_POST['login']; 
$senha=$_POST['senha']; 

// Conecta ao servidor e selecione a database.
 $conn= new mysqli("localhost","root","","registro");
if($conn->connect_error){
die("Falhou a ligação: ".$conn->connect_error);
}
// Proteção contra  MySQL injection 
//$login = stripslashes($login);
//$senha = stripslashes($senha);
//$login = mysqli_real_escape_string($login);
//$senha = mysqli_real_escape_string($senha);

    $result=mysqli_query("SELECT utilizador, senha FROM utilizadores WHERE utilizador='$login' and senha='$senha'");

        $_num=mysqli_num_rows($result);
        if($_num < 1){
            echo " Não esta registado  <br>  faça login <br>";
        }else{
            header;
        }
    exit;
?
  • 1

    Miguel, taking the heat of his question, has even been answered. Since you are using mysqli, I recommend using Prepared Statement and not concatenating variables directly into SQL. I recommend reading: http://mattbango.com/notebook/code/prepared-statements-in-php-and-mysqli/

1 answer

1

You must change the following line:

$result=mysqli_query("SELECT username, password FROM users WHERE username='$login' and password='$password'");

for:

$result=mysqli_query($conn, "SELECT utilizador, senha FROM utilizadores WHERE utilizador='$login' and senha='$senha'");

Notice that before the sql I added the variable $conn. You must pass the connection used and the sql to execute.

You can see more details Clicking Here

Browser other questions tagged

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