Click here to Skip to main content
15,888,081 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to display a few records from my table, but there seems to be a problem with the mysqli part, these are the erros that keeps popping up;

Warning: mysqli_select_db() expects parameter 1 to be mysqli, string given in D:\xampp\htdocs\Project\add_employees.php on line 78

Warning: mysqli_query() expects parameter 1 to be mysqli, string given in D:\xampp\htdocs\Project\add_employees.php on line 79

Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, null given in D:\xampp\htdocs\Project\add_employees.php on line 90
ID Name Phone Number Date Employed Date Unemployed

Can someone explain what the errors mean, and what I'm doing wrong ?

<?PHP
          $conn = new mysqli("localhost","root","");
          mysqli_select_db("kz_komputer",$conn);
          $data = mysqli_query("SELECT * FROM employees",$conn);
          
          echo "<table>
          <tr>
            <th> ID</th>
            <th> Name</th>
            <th> Phone Number</th>
            <th> Date Employed</th>
            <th> Date Unemployed</th>
          </tr>";
          
          while($record = mysqli_fetch_array($data)){
            echo "<tr>";
            echo "<td>" . $record['id'] . "</td>";
            echo "<td>" . $recod['name'] . "</td>";
            echo "<td>" . $record['phone_number'] . "</td>";
            echo "<td>" . $record['date_employed'] . "</td>";
            echo "<td>" . $record['date_unemployed'] . "</td>";
            echo "</tr>";
          }
          echo "</table>";
          
          mysqli_close($conn);
?>


What I have tried:

$conn = new mysql("localhost","root","","kz_komputer");
$sql = "SELECT * FROM employees";
$data = mysql_query($sql,$conn);
Posted
Updated 26-Feb-18 0:38am
Comments
Richard MacCutchan 26-Feb-18 6:36am    
Where are lines 78, 79 and 90?
NexGen39 26-Feb-18 6:40am    
78 - mysqli_select_db
79 - $data
90 - The while loop (mysqli_fetch_array)
Richard MacCutchan 26-Feb-18 7:25am    
See the link below and correct your code.

1 solution

 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900