Getting the errors:
Warning: mysqli_select_db() expects exactly 2 parameters, 1 given in C:\Usersoot\Desktop\WebServer\htdocs\test.php on line 9
Warning: mysqli_query() expects at least 2 parameters, 1 given in C:\Usersoot\Desktop\WebServer\htdocs\test.php on line 13
Warning: mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, null given in C:\Usersoot\Desktop\WebServer\htdocs\test.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>
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);
Yes - if you are going to use the procedural style, pass the return value from mysqli_connect() as the first parameter to mysqli_select_db().
//make connection
$connection = mysqli_connect('localhost', 'root', '');
mysqli_select_db($connection,'altislife-dev');
Note: you could also pass the database name as the 4th parameter of the call to mysqli_connect() - that will select the database.
$connection = mysqli_connect('localhost', 'root', '', 'altislife-dev');
Also, pass the connection handle to the call to mysqli_query:
$records=mysqli_query($connection, $sql);
I dont know If I am misunderstanding the problem because it is very simple and clear in the document => http://php.net/manual/en/mysqli.select-db.php
=> http://php.net/manual/en/mysqli.query.php
You must pass link to function while selecting,
bool mysqli_select_db ( mysqli $link , string $dbname )
Code modifications required
$con_link = mysqli_connect('localhost', 'root', '');
mysqli_select_db($con_link, 'altislife-dev');
$sql="SELECT * FROM players";
$records=mysqli_query($con_link, $sql);