gpt4 book ai didi

php - 表单关闭标签在 php echo 中不起作用?表格元素在编译时相互超越。另外我的 'comment' 输入有什么问题?

转载 作者:行者123 更新时间:2023-11-28 04:12:45 26 4
gpt4 key购买 nike

[PHP] 所以,我正在做一个元素,在这个元素中我必须显示表格中的元素(一个图像和 3 个文本元素),然后在下面提供一个“评论”空间。但是,在网站上检查我的代码时,我的输出 echo 未对齐,并且在检查元素时似乎我的 <td> s 是空的,所有代码都已简单地迁移到新的 <td> .此外,我在底部的添加评论表单,即使我认为是格式正确的关闭标记,也不起作用并最终将所有下面的代码分组在以下 <td> 中。在它之上。我的代码如下:

<html>
<font face="georgia" color="#4c4c4c">
<div
id="wrapper";

background-color:powderblue;color:black;
font-family:sans-serif;
padding:10px;">

<body style="background-color:powderblue;">
<h1> ... </h1>
<table style=cellpadding="1">
<tbody>
<?php
echo" <tr style=\"height: 24px;\"> <td style=\"width: 525px; height: 400px;\">";
$servername = "localhost";
$username = ".";
$password = ".";
$dbname = ".";

// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}

$sql = "SELECT title, price, rating, image, comments FROM uploads";
$result = mysqli_query($conn, $sql);

if (mysqli_num_rows($result) == 1)
{
// output data of each row
if($row = mysqli_fetch_assoc($result))
{
echo "
<img src= \"" . $row["image"] . "\" alt=\"Image Listing\" style=\"width:300px;height:300px;\">
<p>
<b>Title: </b>".$row["title"]. "
</p>
<p>
<b>Price: </b>".$row["price"]. "
</p>
<p>
<b>Rating: </b>".$row["rating"]. "
</p>
<p>
<b>Comments: </b>
<br>".$row["comments"]."<br>";
echo "<form action=comments.php>
<name=\"number\" id=\"number\" value=\"1\">
<br>
<b>Input Comment: </b>
<input type=\"text\" id=\"comments\" name=\"comments\">
<br>
<input type=\"submit\" value=\"Submit\">
<br>
</form>
<br>
<br>";
}
}

echo "</td><td style=\"width: 525px; height: 400px;\">";

if (mysqli_num_rows($result) == 2)
{
// output data of each row
if($row = mysqli_fetch_assoc($result))
{
echo "
<img src= \"" . $row["image"] . "\" alt=\"Image Listing\" style=\"width:300px;height:300px;\">
<p>
<b>Title: </b>".$row["title"]. "
</p>
<p>
<b>Price: </b>".$row["price"]. "
</p>
<p>
<b>Rating: </b>".$row["rating"]. "
</p>
<p>
<b>Comments: </b>
<br>".$row["comments"]."<br>";
echo "<form action=comments.php>
<name=\"number\" id=\"number\" value=\"2\">
<br>
<b>Input Comment: </b>
<input type=\"text\" id=\"comments\" name=\"comments\">
<br>
<input type=\"submit\" value=\"Submit\">
<br>
</form>
<br>
<br>";
}
}
echo "</td></tr><tr style=\"height: 24px;\"><td style=\"width: 525px; height: 400px;\">";

if (mysqli_num_rows($result) == 3) {
// output data of each row
if($row = mysqli_fetch_assoc($result)) {
echo "
<img src= \"" . $row["image"] . "\" alt=\"Image Listing\" style=\"width:300px;height:300px;\">
<p>
<b>Title: </b>".$row["title"]. "
</p>
<p>
<b>Price: </b>".$row["price"]. "
</p>
<p>
<b>Rating: </b>".$row["rating"]. "
</p>
<p>
<b>Comments: </b>
<br>".$row["comments"]."<br>";
echo "<form action=comments.php>
<name=\"number\" id=\"number\" value=\"3\">
<br>
<b>Input Comment: </b>
<input type=\"text\" id=\"comments\" name=\"comments\">
<br>
<input type=\"submit\" value=\"Submit\">
<br>
</form>
<br>
<br>";
}
}
echo "</td><td style=\"width: 525px; height: 400px;\">";

if (mysqli_num_rows($result) == 4) {
// output data of each row
if($row = mysqli_fetch_assoc($result)) {
echo "
<img src= \"" . $row["image"] . "\" alt=\"Image Listing\" style=\"width:300px;height:300px;\">
<p>
<b>Title: </b>" . $row["title"] . "
</p>
<p>
<b>Price: </b>" . $row["price"] . "
</p>
<p>
<b>Rating: </b>" . $row["rating"] . "
</p>
<p>
<b>Comments: </b>
<br>" . $row["comments"] . "<br>";
echo "<form action=comments.php>
<name=\"number\" id=\"number\" value=\4\">
<br>
<b>Input Comment: </b>
<input type=\"text\" id=\"comments\" name=\"comments\">
<br>
<input type=\"submit\" value=\"Submit\">
<br>
</form>
<br>
<br>";
}
}
echo "</td></tr><tr style=\"height: 24px;\"><td style=\"width: 525px; height: 400px;\">";

if (mysqli_num_rows($result) == 5) {
// output data of each row
if($row = mysqli_fetch_assoc($result)) {
echo "
<img src= \"" . $row["image"] . "\" alt=\"Image Listing\" style=\"width:300px;height:300px;\">
<p>
<b>Title: </b>".$row["title"]. "
</p>
<p>
<b>Price: </b>".$row["price"]. "
</p>
<p>
<b>Rating: </b>".$row["rating"]. "
</p>
<p>
<b>Comments: </b>
<br>".$row["comments"]."<br>";
echo "<form action=comments.php>
<name=\"number\" id=\"number\" value=\5\">
<br>
<b>Input Comment: </b>
<input type=\"text\" id=\"comments\" name=\"comments\">
<br>
<input type=\"submit\" value=\"Submit\">
<br>
</form>
<br>
<br>";
}
}

echo "</td><td style=\"width: 525px; height: 400px;\">";

if (mysqli_num_rows($result) == 6) {
// output data of each row
if($row = mysqli_fetch_assoc($result)) {
echo "
<img src= \"" . $row["image"] . "\" alt=\"Image Listing\" style=\"width:300px;height:300px;\">
<p>
<b>Title: </b>".$row["title"]. "
</p>
<p>
<b>Price: </b>".$row["price"]. "
</p>
<p>
<b>Rating: </b>".$row["rating"]. "
</p>
<p>
<b>Comments: </b>
<br>".$row["comments"]."<br>";
echo "<form action=comments.php>
<name=\"number\" id=\"number\" value=\6\">
<br>
<b>Input Comment: </b>
<input type=\"text\" id=\"comments\" name=\"comments\">
<br>
<input type=\"submit\" value=\"Submit\">
<br>
</form>
<br>
<br>";
}
}


mysqli_close($conn);
echo"</td> </tr>"
?>

</tbody>
</table>
</body>
</div>

您对解决我的格式问题有什么想法吗?我的另一个问题是插槽 1、2、3、4、5 和 6 中的安装形式。为什么每当我尝试输入评论时它只会给我预写的错误? comments.php如下:

<?PHP
$dbhost = '.';
$dbuser = '.';
$dbpass = '.';
$db_name = '.';
$tbl_name = 'uploads';

$conn = mysqli_connect($dbhost, $dbuser, $dbpass, $db_name);
if(! $conn )
{
die('Could not connect: ' . mysql_error());
}
mysqli_select_db($conn, $db_name)or die("Cannot select DB");

$comments = (isset($_GET['comments']) ? $_GET['comments'] : null);
$number = (isset($_GET['number']) ? $_GET['number'] : null);
$sql = "UPDATE uploads SET comments=" . $comments . "Where id=" . $number;

if(mysqli_query($conn, $sql))
{
echo 'Upload Successful! Preexisting comments may have been replaced.';
echo '<a href="list.php">Click Here For Current Listings , with your comment
added. </a>';
}
else{echo 'Comment Limit Exceeded! Comment not uploaded.';}
?>

感谢您的任何回答,我已经为此苦苦挣扎了数周。我对此很陌生,因此非常感谢您的帮助。

最佳答案

            if (mysqli_num_rows($result) == 5) {
// output data of each row
if($row = mysqli_fetch_assoc($result)) {

?>

<img src= <?php echo $row["image"]; ?> alt="Image Listing" style="width:300px;height:300px;">
<p>
<b>Title: </b><?php echo $row["title"];?>
</p>
<p>
<b>Price: </b><?php $row["price"];?>
</p>
<p>
<b>Rating: </b><?php echo $row["rating"]; ?>
</p>
<p>
<b>Comments: </b>
<br><?php echo $row["comments"];?><br>
<form action=comments.php>
<name="number" id="number" value="5">
<br>
<b>Input Comment: </b>
<input type="text" id="comments" name="comments">
<br>
<input type="submit" value="Submit">
<br>
</form>
<br>
<br>
<? }?>

</td><td style=\"width: 525px; height: 400px;\">

我会像这样做一些不同的,你可以设计表格让它看起来不错

<html>
<body>

<form name="myform" method="post" action="">
<div style="width:500px;">
<table border="0" cellpadding="10" cellspacing="1" width="500" >
<tr>
<td> row 1</td>
<td> row 2 </td>
<td> row 3 </td>
</tr>
<?php
$result="what ever you want to fetch";
while($row = mysql_fetch_array($result)) {
?>
<td><?php echo $row["row1"]; ?></td>
<td><?php echo $row["row2"]; ?></td>
<td><?php echo $row["row3"]; ?></td>
<?php
}
?>
</body>
</Html>

关于php - 表单关闭标签在 php echo 中不起作用?表格元素在编译时相互超越。另外我的 'comment' 输入有什么问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42638948/

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