代码之家  ›  专栏  ›  技术社区  ›  user3236169

灯堆栈-更新HTML表-不映射到DB或从DB映射

  •  0
  • user3236169  · 技术社区  · 6 年前

    你好,我有一个基本的HTML表单 指数html

    <html>
     <body>
     <form action="update.php" method="POST">
         Department: <input type="text" name="department"><br><br>
         Subname: <input type="text" name="subname"><br><br>
         Labels: <input type="text" name="labels"><br><br>
         Pagerduty: <input type="text" name="pagerduty"><br><br>
         Description: <input type="text" name="description"><br><br>
         <input type="submit" value="Submit" name="submit">
     </form>
    </body>
    </html>
    

    在提交时,将执行以下PHP脚本以使用详细信息更新我的DB。 使现代化php

    <?php
    $hostname = "localhost";
    $username = "root";
    $password = "xxxxxxxxxxx";
    $db = "dora";
    $dbconnect=mysqli_connect($hostname,$username,$password,$db);
    if ($dbconnect->connect_error) {
     die("Database connection failed: " . $dbconnect->connect_error);
    }
    if(isset($_POST['submit'])) {
     $department=$_POST['department'];
     $subname=$_POST['subname'];
     $labels=$_POST['labels'];
     $pagerduty=$_POST['pagerduty'];
     $description=$_POST['description'];
    $query = "INSERT INTO dora (department, subname, labels, pagerduty, description)
    VALUES ('$department', '$subname', '$labels', '$pagerduty', '$description')";
    if (!mysqli_query($dbconnect, $query)) {
          die('An error occurred when submitting your review.');
      } else {
        echo "Thanks for your review.";
      }
      }
    ?>
    

    然后,我希望另一个页面显示一个HTML表,其中包含来自DB的内容 主要的html

    <html>
    <body>
    <?php
    $hostname = "localhost";
    $username = "root";
    $password = "xxxxxxxx";
    $db = "dora";
    $dbconnect=mysqli_connect($hostname,$username,$password,$db);
    if ($dbconnect->connect_error) {
      die("Database connection failed: " . $dbconnect->connect_error);
    }
    ?>
    <table border="1" align="center">
    <tr>
      <td>Department</td>
      <td>Subname</td>
      <td>Labels</td>
      <td>Pagerduty</td>
      <td>Description</td>
    </tr>
    <?php
    $query = mysqli_query($dbconnect, "SELECT * FROM dora")
       or die (mysqli_error($dbconnect));
    
    while ($row = mysqli_fetch_array($query)) {
      echo
       "<tr>
        <td>{$row['department']}</td>
        <td>{$row['subname']}</td>
        <td>{$row['labels']}</td>
        <td>{$row['pagerduty']}</td>
        <td>{$row['description']}</td>
       </tr>\n";
    }
    ?>
    </table>
    </body>
    </html>
    

    除了两列没有相互映射之外,其他一切都正常工作,即 Subname & Labels

    我已经仔细检查了我的代码,但我发现不了错误,有人能帮我吗?

    我重新启动了https等,但似乎没有任何效果:(

    DORA架构

    MariaDB[朵拉]>显示dora中的列;

    +-------------+--------------+------+-----+---------+----------------+
    | Field       | Type         | Null | Key | Default | Extra          |
    +-------------+--------------+------+-----+---------+----------------+
    | TAB_ID      | int(11)      | NO   | PRI | NULL    | auto_increment |
    | department  | varchar(200) | YES  |     | NULL    |                |
    | subname     | varchar(200) | YES  |     | NULL    |                |
    | labels      | varchar(200) | YES  |     | NULL    |                |
    | pagerduty   | varchar(200) | YES  |     | NULL    |                |
    | description | varchar(200) | YES  |     | NULL    |                |
    +-------------+--------------+------+-----+---------+----------------+
    

    我的表格中的结果

    Department  Subname Labels  Pagerduty   Description
    1                             4              5
    1                             4              5
    sdfsdf                        adfasdfad      adfadfadfa
    
    1 回复  |  直到 6 年前
        1
  •  1
  •   USER249    6 年前

    我测试了你的代码,效果很好。唯一的区别是我使用的InnoDB应该是相同的。请尝试以下操作:

    1更改这些列的名称。

    2重新创建数据库。

    3确保没有触发器将两列设置为支架