Skip to content
Advertisement

mysqli_select_db() expects exactly 2 parameters

Getting the errors:

Warning: mysqli_select_db() expects exactly 2 parameters, 1 given in C:UsersrootDesktopWebServerhtdocstest.php on line 9

Warning: mysqli_query() expects at least 2 parameters, 1 given in C:UsersrootDesktopWebServerhtdocstest.php on line 13

Warning: mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, null given in C:UsersrootDesktopWebServerhtdocstest.php on line 39

I can’t notice the problem, kind of new to this, can anyone see the problem?

Any help is very appreciated!

<?php


//make connection
mysqli_connect('localhost', 'root', '');


//select db
mysqli_select_db('altislife-dev');

$sql="SELECT * FROM players";

$records=mysqli_query($sql);

?>

<html>

    <head>

        <title>Data</title>

    </head>

    <body>

        <table width="600" border="1" cellpadding="1" cellspacing="1">
        <tr>
        <th>uid</th>
        <th>name</th>
        <th>aliases</th>
        <th>playerid</th>
        <th>cash</th>
        <th>bankacc</th>
        <th>coplevel</th>
        <tr>

        <?php
        while($players=mysqli_fetch_assoc($records)) {

            echo "<tr>";
            echo "<td>".$players['uid']."</td>";
            echo "<td>".$players['name']."</td>";
            echo "<td>".$players['aliases']."</td>";
            echo "<td>".$players['playerid']."</td>";
            echo "<td>".$players['cash']."</td>";
            echo "<td>".$players['bankacc']."</td>";
            echo "<td>".$players['coplevel']."</td>";
            echo "</tr>";
        }

        ?>
        </table>
    </body>
</html>

Advertisement

Answer

do the correction as below:

$conn = mysqli_connect('localhost', 'root', '');

the first thing that you have to pass connection variable in the select_db as first parameter. as below.

mysqli_select_db($conn,'altislife-dev');

also you have to pass connection variable in mysqli_query() as first parameter as given below.

$records=mysqli_query($conn,$sql);
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement