我的PHP代码说我虽然数据库中没有任何内容。我的代码有什么问题?

时间:2018-09-01 08:18:53

标签: php sql database

    <!DOCTYPE html>
    <html>
    <head>
        <title>Tiger-Gen</title>

        <!-- Compiled and minified CSS -->
        <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0-rc.2/css/materialize.min.css">

        <!-- Compiled and minified JavaScript -->
        <script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0-rc.2/js/materialize.min.js"></script>
                <link href="https://fonts.googleapis.com/css?family=Raleway" rel="stylesheet">
    <link rel="stylesheet" href="main.css">
    </head>

    <body>
        <style>
        .font1 {
            font-family: 'Raleway', sans-serif;
        }
    </style>
        <div class=" container center-align font1 y">
        <h1 class="yeet big">Tiger-Gen</h1>
    <?php 
    include ("connection.php");
        $sql= "SELECT account FROM accs";
        $result = mysqli_query($conn, $sql);

        if (mysqli_num_rows($result) > 0) {
            //output account
            while($row = mysqli_fetch_assoc($result)) {
                echo $row["account"];
            }
        } else {
            echo "nothing";
        }

        mysqli_close($conn);
        ?> 

        <a class="waves-effect waves-light btn center-align btn-large">Generate</a>
    </div>
    </body>




    </html>

Here is my html and php code, I have read over it many and many times and changed my php code multiple times. As you can see it outputs "Nothing" when nothing is in the database. But the problem is there are things in the database, any help is appreciated.

这是我的html和php代码,我已经阅读了很多遍,并且多次更改了我的php代码。如您所见,当数据库中没有内容时,它将输出“ Nothing”。但是问题是数据库中有东西,需要任何帮助。

数据库: https://i.stack.imgur.com/qc1v4.png

帐户表: here

1 个答案:

答案 0 :(得分:0)

嘿,这里显示的不是数据而是列定义

https://i.stack.imgur.com/RaEOQ.png

但是您要查询的是accs表中的数据

$ sql =“选择来自accs的帐户”;

我相信accs表中没有数据,但是您认为列定义是数据

在使用phpMyAdmin时,请使用浏览按钮检查表中是否有数据