Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in SQL by (6.1k points)
edited by

When I am trying to execute my PHP code below, I am getting a fatal error and I am not sure on how to resolve it.

<?php

    $user = 'root';

    $password = 'root';

    $db = 'inventory';

    $host = 'localhost';

    $port = 8888;

    $link = mysqli_init();

    $success = mysqli_real_connect(

       $link,

       $host,

       $user,

       $password,

       $db,

       $port

    );

    ?>

    <?php

    $username = $_POST['username'];

    $password = $_POST['password'];

    $sql = mysql_query("SELECT * FROM login WHERE username = '".$_POST['username']."' and password = '".md5($_POST['password'])."'");

    $row = mysql_num_rows($sql);

    if($rom > 0 )

    {

      session_start();

      $_SESSION['username'] = $_POST['username'];

      $_SESSION['password'] = $_POST['password'];

      echo "login done";

    }else {

      echo "fail login ";

    }

    ?>

The Error

PHP Fatal error: Uncaught Error: Call to undefined function mysql_query() in /Applications/MAMP/htdocs/lprapp/config.php:23 Stack trace:#0 {main} thrown in /Applications/MAMP/htdocs/lprapp/config.php on line 23 

1 Answer

0 votes
by (12.7k points)

You are mixing mysql and mysqli

Change these lines:

$sql = mysql_query("SELECT * FROM login WHERE username = '".$_POST['username']."' and password = '".md5($_POST['password'])."'");

$row = mysql_num_rows($sql);

to

$sql = mysqli_query($success, "SELECT * FROM login WHERE username = '".$_POST['username']."' and password = '".md5($_POST['password'])."'");

$row = mysqli_num_rows($sql);

If you want to learn more about SQL, Check out this SQL Certification by Intellipaat.

For more information visit :

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
asked Dec 19, 2020 in SQL by Appu (6.1k points)
0 votes
1 answer
asked Jul 29, 2019 in SQL by Tech4ever (20.3k points)

Browse Categories

...