【问题标题】:My mysqli table isn't shown properly. I need assistance with my code because I can't find my error我的 mysqli 表显示不正确。我需要有关我的代码的帮助,因为我找不到我的错误
【发布时间】:2018-01-01 17:34:02
【问题描述】:

我正在尝试使用引导程序使这个看起来很漂亮。并且插入工作正常,表格在旧页面上正常工作。但新的显示了这一点。这是相同的代码......实际上 我试图检查所有引用是否都到位,但我发现很难说。但我认为 mysqli_close 和其他一些标志不是正确的地方,但我就是不知道哪里出了问题。我在这里错过了什么?

编辑:替换错位的“”,而且我所有的文件都在同一个文件夹中

EDIT":我发现如果我使用 .php 而不是 .html,它可以正常工作。这是什么意思?如何在我的大型网站中获取它?

<!DOCTYPE html>
<head>
</head>
  <body>
<form action="insert.php" method="post">
  <input type="text" name="nam" placeholder="Title" id="nam"><br>
  <input type="text" name="author" placeholder="Author" id="author"><br>
  <input type="submit" value="Add">
</form>

<div>
  <div style="overflow-x:auto;">
    <table class="table">
      <tr>
        <th>Title</th>
        <th>Author</th>
        <th>Added</th>
        <th>Edit</th>
      </tr>
      <tr>

            <?php
                    include_once "dbConfig.php";
                    $db=mysqli_connect($server, $usr,$pwd,$db);
                            if($db == false){die("no con");}
                            $query = "SELECT * FROM $dbTable";
                            mysqli_query($db, $query) or die('Error');

                            $result = mysqli_query($db, $query);

                            while ($row = mysqli_fetch_assoc($result)){
                                    echo "\t<tr><td>" . $row['name'] . "</td><td>" . $row['author'] .
                                            "</td><td>" . $row[bookread] .
                                            "</td><td><input type='checkbox'" 
                                            value='".$row['name']."'  name='".$row['name']."'</td></tr><br>";
                                    }
                            mysqli_close($db);
                    ?>
            </tr>
    </table>
    </div>
   </div>
  </body>

【问题讨论】:

  • 为什么底部有&lt;/head&gt;?为什么没有打开/关闭html标签?
  • 看起来像未解析的代码。因此,您应该提及您的 PHP 驻留在哪个文件中/它是如何包含的/从哪里/使用了什么模板方法。 -- Als 问题的标题应该是摘要,而不是请求帮助的垃圾邮件。
  • 我对此很陌生。我已经搬了,谢谢
  • 它仍然不是有效的 html - 您缺少 &lt;html&gt;&lt;/html&gt; 标记并且有未闭合的元素
  • "I've discovered that if I use .php instead of .html it works as it should" 这并不奇怪 - 服务器设置为通过 php 解释器运行 .php 文件,但只返回 .html 文件的内容

标签: php html mysql mysqli


【解决方案1】:

不支持 PHP。通过编辑php.ini解决

【讨论】:

    【解决方案2】:
                            while ($row = mysqli_fetch_assoc($result)){
                                    echo "\t<tr><td>" . $row['name'] . "</td><td>" . $row['author'] .
                                            "</td><td>" . $row['bookread'] .
                                            "</td><td><input type='checkbox'
                                            value='".$row['name']."'  name='".$row['name']."'</td></tr><br>";
                                    }
                            mysqli_close($db);
    

    【讨论】:

    • 上述内容存在原始问题之一 - input 元素仍未关闭
    【解决方案3】:

    那里有几个基本的 HTML 错误 - 没有 html 标记、没有 title、带有错误引号的未关闭输入元素以及其他一些错误。我敦促您正确缩进您的代码 - 它总是更容易发现错误并遵循结构/逻辑。

    您拥有的 sql (可能)容易受到 sql 注入的影响,您应该在尝试迭代之前检查是否有可用的记录集。

    <!DOCTYPE html>
    <html>
        <head>
            <title></title>
        </head>
        <body>
            <form action="insert.php" method="post">
              <input type="text" name="nam" placeholder="Title" id="nam"><br>
              <input type="text" name="author" placeholder="Author" id="author"><br>
              <input type="submit" value="Add">
            </form>
    
            <div>
                <div style="overflow-x:auto;">
                    <table class="table">
                        <tr>
                            <th>Title</th>
                            <th>Author</th>
                            <th>Added</th>
                            <th>Edit</th>
                        </tr>
    
    
                        <?php
    
                            include_once "dbConfig.php";
                            $db=mysqli_connect($server, $usr,$pwd,$db);
    
                            if($db == false){die("no con");}
    
                            $query = "SELECT * FROM $dbTable";  /* this makes it potentially vulnerable */
                            mysqli_query($db, $query) or die('Error');
    
                            $result = mysqli_query( $db, $query );
    
                            if( $result && mysqli_num_rows( $result ) > 0 ){
    
                                while ( $row = mysqli_fetch_assoc( $result ) ){
                                    echo "
                                        <tr>
                                            <td>{$row['name']}</td>
                                            <td>{$row['author']}</td>
                                            <td>{$row['bookread']}</td>
                                            <td><input type='checkbox' value='{$row['name']}' name='{$row['name']}' /></td>
                                        </tr>";
                                }
                            }
                            mysqli_close($db);
                        ?>
    
                    </table>
                </div>
            </div>
        </body>
    </html>
    

    【讨论】:

      猜你喜欢
      • 2018-02-07
      • 1970-01-01
      • 2020-01-09
      • 2021-09-05
      • 2014-08-22
      • 2021-05-05
      • 2010-09-23
      • 2021-02-07
      • 1970-01-01
      相关资源
      最近更新 更多