0

I just started with mysql and php.

I am trying to show mysql database in a table. It seems like the code is working but it gives 0 results. I have 2 rows in mysql table.

<!DOCTYPE html>
<html lang="en">
<head>
  <title>Tronios Exportzendingen</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  <link rel="stylesheet" type="text/css" href="styles2.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
    <?php
        $servername = "localhost";
        $username = "rubinjo13";
        $dbname = "project1";

        // Create connection
        $conn = new mysqli($servername, $username, $password, $dbname);
        // Check connection
        if ($conn->connect_error) {
             die("Connection failed: " . $conn->connect_error);
        } 

        $sql = "ExportID, Debiteur, Deb_Name, Tot_Pallets, Tot_Weight, PBS FROM export";
        $result = $conn->query($sql);

        if ($result->num_rows > 0) {
             echo "<table><tr><th>ID</th><th>Debiteur</th><th>Naam</th><th>Aantal Pallets</th><th>Totaal Gewicht</th><th>PB Nummers</th></tr>";
             // output data of each row
             while($row = $result->fetch_assoc()) {
                 echo "<tr><td>" . $row["ExportID"]. "</td><td>" . $row["Debiteur"]. " " . $row["Deb_Name"]. "</td></tr>"
                 . $row["Tot_Pallets"]. "</td><td>" . $row["Tot_Weight"]. "</td><td>" . $row["PBS"]. "</td><td>"; 
             }
             echo "</table>";
        } else {
             echo "0 results";
        }

        $conn->close();
        ?>  
</body>
</html>

Hope somebody can help me out:)

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Rubinjo13
  • 65
  • 2
  • 11

1 Answers1

1

You missed the SELECT in the query:

$sql = "SELECT ExportID, Debiteur, Deb_Name, Tot_Pallets, Tot_Weight, PBS FROM export";
Dez
  • 5,702
  • 8
  • 42
  • 51