0

This is my code:

<?php 
    $host="localhost";
    $user ="wwwroot";
    $password="";
    $db="demo";


    mysql_connect($host,$user,$password);
    mysql_select_db($db);

    if(isset($_POST['username'])){
        $uname=$_POST['username'];
        $password=$_POST['password'];

        $sql="select * from loginform where user='".$uname."'AND pass='".$password."' limit 1";

        $result = mysql_query($sql);

        if(mysql_num_rows($result)== 1){

            echo "you have successfully logged in";
        }
        else{
            echo "you have entered incorrect password";

            exit();
        }
    }

?>

And this is the error:

Fatal error: Uncaught Error: Call to undefined function mysql_connect() in C:\Users\lenovo\login\login.php:9 Stack trace: #0 {main} thrown in C:\Users\lenovo\login\login.php on line 9

How can I fix this?

halfer
  • 19,471
  • 17
  • 87
  • 173
  • **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 Mar 31 '20 at 14:34

1 Answers1

-2

Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead

Check : https://www.w3schools.com/php/func_mysqli_query.asp

https://www.php.net/manual/en/book.mysqli.php

https://websitebeaver.com/prepared-statements-in-php-mysqli-to-prevent-sql-injection

Devanarayanan
  • 13
  • 1
  • 6