• Register
1 vote
1.6k views

Problem :

I am very new to mysqli. Currently I am working on program and getting below errors:

Warning: mysqli_select_db() expects exactly 2 parameters, 1 given in C:\Users\root\Desktop\WebServer\htdocs\test.php on line 9

Warning: mysqli_query() expects at least 2 parameters, 1 given in C:\Users\root\Desktop\WebServer\htdocs\test.php on line 13

Warning: mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, null given in C:\Users\root\Desktop\WebServer\htdocs\test.php on line 39

As I am very new to mysqli so I am unable to notice any problem in my code. Can someone help me in fixing above error.

Please find below my code:

<?php
//code to make connection
mysqli_connect('localhost', 'root', '');
//code to select db
mysqli_select_db('myaltislife-dev');
$mysql="SELECT * FROM myplayers";
$myrecords=mysqli_query($mysql);
?>
<html>

    <head>

        <title>MyData</title>

    </head>

    <body>

        <table width="600" border="1" cellpadding="1" cellspacing="1">
        <tr>
        <th>myuid</th>
        <th>myname</th>
        <th>myaliases</th>
        <th>myplayerid</th>
        <th>mycash</th>
        <th>mybankacc</th>
        <th>mycoplevel</th>
        <tr>

        <?php
        while($myplayers=mysqli_fetch_assoc($myrecords)) {

            echo "<tr>";
            echo "<td>".$myplayers['myuid']."</td>";
            echo "<td>".$myplayers['myname']."</td>";
            echo "<td>".$myplayers['myaliases']."</td>";
            echo "<td>".$myplayers['myplayerid']."</td>";
            echo "<td>".$myplayers['mycash']."</td>";
            echo "<td>".$myplayers['mybankacc']."</td>";
            echo "<td>".$myplayers['mycoplevel']."</td>";
            echo "</tr>";
        }

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

 

9 6 2
3,980 points

Please log in or register to answer this question.

1 Answer

1 vote

Solution :

You need to do the correction as shown below:
$myconn = mysqli_connect('localhost', 'root', '');

A very first thing that you must pass to your connection variable in your select_db as first parameter is as shown below.

mysqli_select_db($myconn,'myaltislife-dev');

After that you must pass your connection variable in the mysqli_query() as the first parameter as shown below.

$myrecords=mysqli_query($myconn,$mysql);
After making above changes your issue will be fixed.
5 4 2
17,150 points

Related questions

0 votes
1 answer 70 views
70 views
I require to know what is parameter is being asked of me to give. Can someone give me the hint how to solve this issue?
asked Sep 14, 2020 Daniel Anderson 4k points
1 vote
1 answer 104 views
104 views
Problem: I am very new to PHP Programming. I want to convert the Wordpress theme from the PHP 5.4 to 7.1 But while trying to do it I am facing below error : Warning: mysqli_real_escape_string() expects exactly 2 parameters, 1 given in /home/myhost/wp-content/themes/ ... } I am trying to fix above PHP error but still unable to fix it. Please guide me in fixing above strange looking PHP error.
asked May 28, 2020 Martin K 6.6k points
0 votes
1 answer 23 views
23 views
Problem: I get the following error Warning: mysqli_error() expects exactly 1 parameter, 0 given
asked Mar 15 ummesalma 29.2k points
0 votes
1 answer 118 views
0 votes
1 answer 113 views
113 views
This issue stuck in my path "Warning: mysqli_query() expects at least 2 parameters, 1 given". I am finding the solution in several blogs and lot's of opinion coming. Can someone provide me the specific solution and script for solving this issue?
asked Sep 14, 2020 Daniel Anderson 4k points
1 vote
1 answer 12 views
12 views
Problem: I am getting these errors but need solution: Warning: mysqli_select_db() expects parameter 1 to be mysqli.
asked Apr 28 PkGuy 23.5k points
1 vote
1 answer 135 views
135 views
Problem: I am very new to the Mysqli_*. I have currently started understanding it. I am facing following errors: Warning: mysqli_select_db() expects parameter 1 to be mysqli, string given in D:\Hosting\9864230\html\includes\connection.php on line 11 Warning: mysqli_error( ... ) {     die("The Database selection failed: " . mysqli_error()); } ?> Kindly help me in neutralizing above errors.
asked May 28, 2020 Martin K 6.6k points
0 votes
1 answer 96 views
96 views
Problem: mysqli_error() expects exactly 1 parameter, 0 given
asked Feb 15 Sabbir Hossain 14.6k points
0 votes
1 answer 19 views
19 views
Problem: I am getting this .. can you help me to solve it? Warning: mysqli_query() expects at least 2 parameters,
asked Apr 26 Ifra 37.2k points