gpt4 book ai didi

php - 如何让我的 html 代码以有效的方式输出数据?

转载 作者:行者123 更新时间:2023-11-29 06:14:51 25 4
gpt4 key购买 nike

我正在尝试输出我的 MySQL 用户表的内容,我以一种管理员可以在表中添加、编辑和删除行的方式设置了代码。然而,在进一步研究这个问题之后,我发现 html 代码以一种尴尬的方式输出值,因为它只将列中的第一个单词计为有效值,所以它忽略了其他单词。我该如何解决这个问题?

例如,假设我正在尝试输出一张名为 Skulls & Bones 的专辑,那么 table 上的输出将只是 Skulls。

Admin_Album_Page.php

<!DOCTYPE HTML>
<html>
<head>
<title>View Album Table</title>
</head>
<body>

<?php

error_reporting(E_ALL);
ini_set('display_errors', 1);

session_start();
require_once 'ConnectorCode.php';

//mysql_query command is used to select data from Albums table
$result = mysqli_query($conn, "SELECT * FROM tbl_Albums");

//Echos setting established onto the main table
echo "<table border='1'>";
echo "<tr> <th>Album ID</th> <th>Album Name</th> <th>Number Of Tracks</th>
<th> Genre </th> <th>Track ID</th> </tr>";

//Results are looped and then displayed in tables while($row = mysqli_fetch_array($result)) {
echo "<form action=Admin_Album_Page.php method=post>";
echo "<tr>";
echo "<td>" . "<input type=number name=albumid value=" . $row['Album_id'] . " </td>";
echo "<td>" . "<input type=text name=albumname value=" . $row['Album_Name'] . " </td>";
echo "<td>" . "<input type=number name=numberoftracks value=" . $row['Number_Of_Tracks'] . " </td>";
echo "<td>" . "<input type=text name=genre value=" . $row['Genre'] . " </td>" ;
echo "<td>" . "<input type=number name=artistid value=" . $row['Artist_id'] . " </td>";
echo "<td>" . "<input type=hidden name=hidden value=" . $row['Album_id'] . " </td>";
echo "<td>" . "<input type=submit name=update value=Update" . " </td>";
echo "<td>" . "<input type=submit name=delete value=Delete" . " </td>";
echo "</form>";
}

echo "<form action=Admin_Artist_Page.php method=post>";
echo "<tr>";
echo "<td></td>";
echo "<td><input type=text name=ualbumname></td>";
echo "<td><input type=text name=unumberoftracks></td>";
echo "<td><input type=text name=ugenre></td>";
echo "<td><input type=number name=uartistid></td>";
echo "<td>" . "<input type=submit name=add value=Add" ." </td>";
echo "</form>";
echo "</table>";

//Connection is closed
mysqli_close($conn);
?>


<p><a href="Admin.php">Return to main page</a></p>
</body>
</html>

最佳答案

问题出在您的 HTML 呈现中。

您需要将代码更改为:

echo "<form action=\"Admin_Album_Page.php\" method=\"post\">";
echo "<tr>";
echo "<td>" . "<input type=\"number\" name=\"albumid\" value=\"" . $row['Album_id'] . "\" </td>";
echo "<td>" . "<input type=\"text\" name=\"albumname\" value=\"" . $row['Album_Name'] . "\" </td>";
echo "<td>" . "<input type=\"number\" name=\"numberoftracks\" value=\"" . $row['Number_Of_Tracks'] . "\" </td>";
echo "<td>" . "<input type=\"text\" name=genre value=" . $row['Genre'] . " </td>" ;
echo "<td>" . "<input type=\"number\" name=\"artistid\" value=\"" . $row['Artist_id'] . "\" </td>";
echo "<td>" . "<input type=\"hidden\" name=\"hidden\" value=\"" . $row['Album_id'] . "\" </td>";
echo "<td>" . "<input type=\"submit\" name=\"update\" value=\"Update" . "\" </td>";
echo "<td>" . "<input type=\"submit\" name=\"delete\" value=\"Delete" . "\" </td>";
echo "</form>"

echo "<form action=\"Admin_Artist_Page.php\" method=\"post\">";
echo "<tr>";
echo "<td></td>";
echo "<td><input type=\"text\" name=\"ualbumname\"></td>";
echo "<td><input type=\"text\" name=\"unumberoftracks\"></td>";
echo "<td><input type=\"text\" name=\"ugenre\"></td>";
echo "<td><input type=\"number\" name=\"uartistid\"></td>";
echo "<td>" . "<input type=\"submit\" name=\"add\" value=\"Add" ."\" </td>";
echo "</form>";
echo "</table>";

解释:

HTML 的工作方式如下:

<tag attribute="value"></tag>

你不能简单地调用它

<tag attribute=value></tag>

在我向您展示的代码中,您要确保 "符号是字符串的一部分,因此您可以使用 \ 对其进行转义

关于php - 如何让我的 html 代码以有效的方式输出数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36429344/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com