我基本上有一个输入系统,人们输入数据,数据以特定的顺序打印在HTML表格中。
我有一些代码在下面工作正常,除了每次更新行时,编辑表而不是添加带有数据的新表。当我刷新数据消失时?
我的代码如下:
$query = "SELECT * FROM rumours";
$query = mysql_query($query) or die('MySQL Query Error: ' . mysql_error( $connect ));
while ($row = mysql_fetch_assoc($query)) {
$id = $row['id'];
$band = $row['band'];
$title = $row['Title'];
$description = $row['description'];
}
$sql="INSERT INTO rumours (band, Title, description)
VALUES
('$_POST[firstname]','$_POST[lastname]','$_POST[age]')";
if (!mysql_query($sql,$connect))
{
die('Error: ' . mysql_error());
}
if (mysql_query($sql, $connect)) {
echo "<table border='1'>";
echo "<tr>";
echo "<td> $title </td>";
echo "</tr>";
echo "<tr>";
echo "<td class = 'td1'> $description </td>";
echo "</tr>";
echo "</table>";
}
echo "1 record added";
mysql_close($connect);
答案 0 :(得分:0)
您只是从 inserted db行生成表,而不是db表中的所有db行。为此,您还需要echo
每个找到的行的表代码:
$query = "SELECT * FROM rumours";
$query = mysql_query($query) or die('MySQL Query Error: ' . mysql_error( $connect ));
while ($row = mysql_fetch_assoc($query)) {
$id = $row['id'];
$band = $row['band'];
$title = $row['Title'];
$description = $row['description'];
echo "<table border='1'>";
echo "<tr>";
echo "<td> $title </td>";
echo "</tr>";
echo "<tr>";
echo "<td class = 'td1'> $description </td>";
echo "</tr>";
echo "</table>";
}
$sql="INSERT INTO rumours (band, Title, description)
VALUES
('$_POST[firstname]','$_POST[lastname]','$_POST[age]')";
/* ... Code truncated to save space */