0

I'm trying to do a simple login and I found this code that uses MySQL for that, but my website uses mysqli

I tried to change it myself but crashes the website, is there a mysqli equivalent for this piece of code?

What I want to change

$result=mysql_query($sql);

            if(mysql_num_rows($result)==1){
                echo " You Have Successfully Logged in";
                header("location: menu.html");
            }
            else{
                echo " You Have Entered Incorrect Password";
                exit();
            }

I don't know if this helps, but here is what I have before that piece of code


$server = I;
$usuario = WONT;
$pass = SHOW;
$database= THIS;

$mysqli = new mysqli($server, $usuario, $pass, $database);
            echo "estoy aqui";
            $uname=$_POST['usuario'];
            $password=$_POST['password'];

            $sql = $mysqli -> query ("select * from USUARIOS where usuario='".$uname."'AND password='".$password."' limit 1");

            $result=mysql_query($sql);
Hugo
  • 149
  • 6
  • mysql and mysqli are practically the same thing ... just replace mysql with mysqli in all the function names – mega12345mega May 14 '20 at 02:10
  • ^^^ Yes but look at manual pages for each function to make sure you know what each function expects. What is this `$result=mysql_query($sql);` in the new code??? – AbraCadaver May 14 '20 at 02:13
  • 1
    [Use password_hash](https://code-boxx.com/password-encrypt-decrypt-php/) and prepared statements to prevent the vulnerabilities of SQL injection and exposed passwords in your database. – danblack May 14 '20 at 02:16
  • [msqli_execute](https://www.php.net/manual/en/mysqli.quickstart.prepared-statements.php) can be used for prepared statements too. – danblack May 14 '20 at 02:17
  • 2
    `mysqli_query($link, $sql)` needs a link that is from `$link = mysqli_connect(...)` , –  May 14 '20 at 02:27
  • @mega12345mega that is not true.please read the docs –  May 14 '20 at 02:29
  • @MaxMuster Could you link where this is stated? I always thought that adding the "i" always worked. – mega12345mega May 14 '20 at 02:31
  • @mega https://stackoverflow.com/a/56997881/1839439 – Dharman May 14 '20 at 10:51

0 Answers0