为什么命令回声php打印出糟糕的线html



我是PHP上的新手因此,所需的一个产生了运输返回错误的错误。这是PHP

<?php 
$conn = mysqli_connect("localhost", "username", "password", "database_name");
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
$query="SELECT * FROM ingrediente";
$result = mysqli_query($conn, $query);
if (mysqli_num_rows($result) > 0) {
// output data of each row
while($row = mysqli_fetch_assoc($result)) {
   $name = $row["id_ingrediente"];
   $value = $row["immagine"];
   $etichetta = $row["nome"];
   $prezzo = $row["costo_unitario"];
    echo "n";
    echo "<input type='checkbox' name=$name value='$value' onchange="add_ing2($name,'$value','$etichetta',$prezzo,this);">$etichetta" ;
    echo "n";
    echo "<input type='number' name='$etichetta' style='border:0px; text-align:right;background:transparent; height:auto;' value=$prezzo readonly> €";
    echo "n";
    echo "<br><br>";
  }
} else {
echo "0 results";
}
mysqli_close($conn);
?>

这是生产的HTML

<input type='checkbox' name=1 value='/images/ingredienti/pomodoro.png' onchange="add_ing2(1,'/images/ingredienti/pomodoro.png','Pomodoro',0.3,this);">Pomodoro
<input type='number' name='Pomodoro' style='border:0px; text-align:right;background:transparent; height:auto;' value=0.3 readonly> €
<br><br>
<input type='checkbox' name=2 value='/images/ingredienti/formaggio.png
' onchange="add_ing2(2,'/images/ingredienti/formaggio.png
','Formaggio',0.2,this);">Formaggio
<input type='number' name='Formaggio' style='border:0px; text-align:right;background:transparent; height:auto;' value=0.2 readonly> €
<br><br>
<input type='checkbox' name=3 value='/images/ingredienti/hamburger.png
' onchange="add_ing2(3,'/images/ingredienti/hamburger.png
','Hamburger',1,this);">Hamburger
<input type='number' name='Hamburger' style='border:0px; text-align:right;background:transparent; height:auto;' value=1 readonly> €
<br><br>

您可以看到正确的打印方法仅应用于第一个元素(pomodoro(html代码中的1:2行((。既然这在使用复选框时会引起我的数量,那么我可以解决?

我可以解决吗?

非常感谢

php没错 - 从数据库中提取的数据很糟糕。您的一些图像路径在最后具有新的字符。

您应该最终修复数据(验证用户输入,调整自动将其拉动的脚本等(,但是您可以将trim()应用于值以剥离额外字符的值。

错误的假设!您的$价值似乎在最后也有断线。 您可以看到图像URL之后的线路断开。所以寻找一个 n图像值。提示:$ value = trim($ value(;[更新] do trim(( 在所有使用的变量上。 - @Justonunder数百万

看来您的数据有不错的数据。看看 数据库 - 我敢打赌,您会在原始数据中看到它们。你可以试试 修剪值,但最好解决基本问题。 - @ceejayoz

我将Trim((应用于所有变量,并且有效!!!Thx如此多的Justonulder Million和Ceejayox&lt; 3

最新更新