-3

我有一个 php 文件,其中有一个带有复选框的表,其值等于 MYSQL 表中的 ID。当我运行它时,我得到了错误。我知道“和”有一些问题,有人可以帮助解决这个问题吗?

    while ($row = mysqli_fetch_array($result))
    {
    echo "<tr>";
    ***//I get error in the following line*** 
    echo"<td> <form action="del_prod.php" method="post">input type="checkbox" name="product_id" value="$row["product_id"]"></td>"
    echo "<td>" . $row['product_id'] . "</td>";
    echo "<td >" . $row['product_name'] . "</td>";
    echo "<td>" . $row['weight'] . "</td>";
    echo "</tr>";
    }
    echo "</table>";
    ?>
4

9 回答 9

4

你的线路有几个问题。

echo "<td><form action=\"del_prod.php\" method=\"post\"><input type=\"checkbox\" name=\"product_id\" value=\"".$row['product_id']."\" /></td>";
  • 你没有逃避双引号。
  • 您缺少输入标记上的开头 <。
  • 您没有关闭输入标签。
  • 您没有正确连接字符串中的 $row['product_id'] 。
  • 你少了一个分号。

除了 form 标签不应该在<td>. 它应该在桌子外面,或者更好的是根本没有桌子!:)

于 2013-02-05T10:08:35.410 回答
0
echo"<td><form action='del_prod.php' method='post'><input type='checkbox' name='product_id' value='".$row['product_id']."'></td>";
于 2013-02-05T10:07:01.173 回答
0

改变 -

echo"<td> <form action="del_prod.php" method="post">input type="checkbox" name="product_id" value="$row["product_id"]"></td>";

echo'<td> <form action="del_prod.php" method="post">input type="checkbox" name="product_id" value="$row["product_id"]"></td>';

你的报价在最后conflicting没有;

于 2013-02-05T10:07:10.367 回答
0

你错过;了这一行,也逃脱了"双引号。

echo"<td> <form action=\"del_prod.php\" method=\"post\"><input type=\"checkbox\" name=\"product_id\" value=\"$row[\"product_id\"]\"></td>";
于 2013-02-05T10:07:25.050 回答
0

您必须转义引号并且缺少半列,您可以像这样更正

echo"<td> <form action=\"del_prod.php\" method=\"post\">input type=\"checkbox\" name=\"product_id\" value=".$row["product_id"]."></td>";

或者,您可以使用单引号使生活更轻松。

此链接可能会有所帮助: http: //php.net/manual/en/language.types.string.php

于 2013-02-05T10:07:31.803 回答
0

您必须"像这样在您的声明中转义:

echo'<td> <form action="del_prod.php" method="post">input type="checkbox" name="product_id" value="' . $row["product_id"] . '"></td>';
于 2013-02-05T10:07:36.437 回答
0

代替

echo"<td> <form action="del_prod.php" method="post">input type="checkbox" name="product_id" value="$row["product_id"]"></td>"

echo"<td> <form action='del_prod.php' method='post'>input type='checkbox' name='product_id' value='$row['product_id']'></td>"

您可以在 echo strong 中使用单引号。

于 2013-02-05T10:08:53.037 回答
0

代码应该写成

while ($row = mysqli_fetch_array($result))
{
    echo "<tr>";
    //I get error in the following line*** 
    echo "<td> 
        <form action='del_prod.php' method='post'>
            <input type='checkbox' name='product_id' value='".$row["product_id"]."'/>
        </form>
    </td>";
    echo "<td>" . $row['product_id'] . "</td>";
    echo "<td >" . $row['product_name'] . "</td>";
    echo "<td>" . $row['weight'] . "</td>";
    echo "</tr>";
}
echo "</table>";
于 2013-02-05T10:10:43.087 回答
0
 while ($row = mysqli_fetch_array($result))
    {
    echo "<tr>";
    //***//I get error in the following line*** 
    echo"<td> <form action=\"del_prod.php\" method=\"post\">input type=\"checkbox\ name=\"product_id\" value=\"$row['product_id']\"></td>";
    echo "<td>" . $row['product_id'] . "</td>";
    echo "<td >" . $row['product_name'] . "</td>";
    echo "<td>" . $row['weight'] . "</td>";
    echo "</tr>";
    }
    echo "</table>";
于 2013-02-05T10:26:16.887 回答