-5

I have a problem in my Login Page. After I click login it will show me this error.

Fatal error: Uncaught ArgumentCountError: mysqli_query() expects at least 2 arguments, 1 given in C:\xampp\htdocs\script.php:24 Stack trace: #0 C:\xampp\htdocs\script.php(24): mysqli_query('select * from L...') #1 C:\xampp\htdocs\index.html(15): include('C:\xampp\htdocs...') #2 {main} thrown in C:\xampp\htdocs\script.php on line 24

<?php

$servername = "localhost";
$username = "root";
$password = "";
$dbname = "Account";

// Create Connection
$conn = new mysqli($servername, $username, $password, $dbname);

// Check Connection
if($conn->connect_error){
    die("Connection Failed: " . $conn->connect_error);
}
echo "Connected Successfully";


if(isset($_POST['Email'])){
    $email=$_POST['Email'];
    $password=$_POST['Pass'];

    $sql = "select * from Login Page where Email='$email' AND Pass='$password' limit 1";

    $result=mysqli_query($sql);

    if(mysql_num_rows($result==1)){
        echo "Login Successful!";
        exit();
    }
    else {
        echo "Incorrect credentials! Login Failed!";
    }
}

?>
Larz Jhin
  • 1
  • 1
  • 1
    Reading the error message and the corresponding page for [mysqli_query](https://www.php.net/manual/en/mysqli.query.php) will show a very obvious difference when looking at your code that uses `mysqli_query`. – danblack May 05 '22 at 04:49
  • Or at least google the error message – Your Common Sense May 05 '22 at 05:01
  • Would have taken you a lot less time to Google the error than to create an account and post the code here, just to get the same answer. Always search first! – ADyson May 05 '22 at 06:08
  • 1
    **Warning:** You are wide open to [SQL Injections](https://php.net/manual/en/security.database.sql-injection.php) and should use parameterized **prepared statements** instead of manually building your queries. They are provided by [PDO](https://php.net/manual/pdo.prepared-statements.php) or by [MySQLi](https://php.net/manual/mysqli.quickstart.prepared-statements.php). Never trust any kind of input! Even when your queries are executed only by trusted users, [you are still in risk of corrupting your data](http://bobby-tables.com/). [Escaping is not enough!](https://stackoverflow.com/q/32391315) – Dharman May 05 '22 at 07:37
  • 1
    **Never store passwords in clear text or using MD5/SHA1!** Only store password hashes created using PHP's [`password_hash()`](https://php.net/manual/en/function.password-hash.php), which you can then verify using [`password_verify()`](https://php.net/manual/en/function.password-verify.php). Take a look at this post: [How to use password_hash](https://stackoverflow.com/q/30279321/1839439) and learn more about [bcrypt & password hashing in PHP](https://stackoverflow.com/a/6337021/1839439) – Dharman May 05 '22 at 07:37

0 Answers0