Click here to Skip to main content
15,882,055 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
<body class="hold-transition login-page">
<?php
  require('db.php');
  session_start();
    
    if (isset($_POST['username']))
    {
        $username = $_POST['username'];
        $password = $_POST['password'];

        $username = stripslashes($username);
        $username = $mysqli->real_escape_string($username);

        $password = stripslashes($password);
        $password = $mysqli->real_escape_string($password);

        
        $query = "SELECT * FROM `user` WHERE username='$username' and password='$password'";
        $result = $mysqli->query($query) or die($mysqli->error);
        $rows = $result->num_rows;


What I have tried:

i actually converted the code from mysql to mysqli.
Posted
Updated 28-Nov-22 4:19am
Comments
Chris Copeland 28-Nov-22 9:44am    
That error means that it cannot find a variable named $mysqli. You may have converted your code and forgotten to rename some variables?
Richard Deeming 29-Nov-22 4:22am    
Your code is vulnerable to SQL Injection[^]. NEVER use string concatenation/interpolation to build a SQL query. ALWAYS use a parameterized query. PHP: SQL Injection - Manual[^]
Richard Deeming 29-Nov-22 4:23am    
Also, you are storing your users' passwords in plain text. Don't do that, unless you want a multi-million dollar fine for not securing your users' data properly!

Secure Password Authentication Explained Simply[^]

PHP: password_hash[^]
PHP: password_verify[^]

1 solution

The variable $mysqli must be a created instance of the mysqli class. See PHP: Dual procedural and object-oriented interface - Manual[^] for details.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900