0

I am trying to create a login page. But i have a problem to login the page. My login page is

<!DOCTYPE html>
<html>
<head>
    <title>Login Page</title>
    <link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
    <div id="frm">
        <form action="process.php" method="POST">
            <p>
                <label>Username:</label>
                <input type="text" id="user" name="user" />
            </p>
            <p>
                <label>Password:</label>
                <input type="password" id="pass" name="pass" />
            </p>
            <p>
                <input type="submit" id="btn" value="Login"/>
            </p>
        </form>
    </div>
</body>
</html>

My process.php file is

<?php
    $username=$_POST['user'];
    $password=$_POST['pass'];

    $username = stripcslashes($username);
    $password = stripcslashes($password);
    $username = mysql_real_escape_string($username);
    $password = mysql_real_escape_string($password);

    mysql_connect("localhost","root","");
    mysql_select_db("login");

    $result = mysql_query("select * from users where username='$username' and password = '$password' ") or die("Failed to query database".mysql_error());
    $row = mysql_fetch_array($result);

    if($row['username']==$username && $row['password'] == $password){
        echo"Login success!!! Welcome ".$row['username'];

    }
    else{
        echo"Login Fail ";
    }

?>

But i get the error

Fatal error: Uncaught Error: Call to undefined function mysql_real_escape_string() in C:\xampp\htdocs\php\process.php:7 Stack trace: #0 {main} thrown in C:\xampp\htdocs\php\process.php on line 7

Purpose of this code is to login a page with a particular username and password which are already store in database.

Senthuja
  • 520
  • 1
  • 7
  • 19
  • What version of PHP are you running? The `mysql_*` functions have been deprecated since version 5.5 and removed since version 7. – Nick May 05 '19 at 05:24
  • If you're running PHP<7, the second duplicate will offer some suggestions as to what your problem might be. – Nick May 05 '19 at 05:29
  • PHP 7.2.10 . This is the version i am used – Senthuja May 05 '19 at 05:36
  • You will need to convert to [`mysqli`](https://www.php.net/manual/en/book.mysqli.php) or [`PDO`](https://www.php.net/manual/en/class.pdo.php) then... – Nick May 05 '19 at 05:37
  • See https://stackoverflow.com/questions/1390607/how-to-change-mysql-to-mysqli and https://stackoverflow.com/questions/28096054/how-to-replace-mysql-functions-with-pdo – Nick May 05 '19 at 05:39
  • Still I get some warnings:Warning: mysqli_real_escape_string() expects exactly 2 parameters, 1 given in C:\xampp\htdocs\php\process.php on line 7 Warning: mysqli_real_escape_string() expects exactly 2 parameters, 1 given in C:\xampp\htdocs\php\process.php on line 8 Warning: mysqli_select_db() expects exactly 2 parameters, 1 given in C:\xampp\htdocs\php\process.php on line 11 Warning: mysqli_query() expects at least 2 parameters, 1 given in C:\xampp\htdocs\php\process.php on line 13 Warning: mysqli_error() expects exactly 1 parameter, 0 given in C:\xampp\htdocs\php\process.php – Senthuja May 05 '19 at 05:41
  • 1
    Unfortunately it's not as simple as just changing the word `mysql` to `mysqli`. :-( If you read this question https://stackoverflow.com/questions/1390607/how-to-change-mysql-to-mysqli it has information on some other things you will need to change. – Nick May 05 '19 at 05:44

0 Answers0