LAMP 堆栈 - 更新 HTML Table - 不映射 to/from 数据库
LAMP Stack - Update HTML Table - Not mapping to/from DB
你好,我有一个基本的 HTML 表格 Index.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 脚本以使用详细信息更新我的数据库。 update.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 table 以及数据库中的内容 Main.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]> 显示来自 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 | |
+-------------+--------------+------+-----+---------+----------------+
我的结果 table
Department Subname Labels Pagerduty Description
1 4 5
1 4 5
sdfsdf adfasdfad adfadfadfa
我测试了您的代码,它工作正常。唯一的区别是我使用的 InnoDB 应该是相同的。请尝试以下操作:
1 更改这些列的名称。
2 重新创建您的数据库。
3 确保没有触发器将两列设置为 plank