我有一个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>";
?>
您的线路有几个问题。
echo "<td><form action='"del_prod.php'" method='"post'"><input type='"checkbox'" name='"product_id'" value='"".$row['product_id']."'" /></td>";
- 你不能逃避双引号
- 您错过了开头<在输入标签上
- 您没有关闭输入标记
- 您没有正确连接字符串中的$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"<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
,在末尾缺少;
您在这一行中遗漏了;
,也转义了"
双引号。
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>";
或者,你可以使用单引号让生活更轻松。
此链接可能有助于:http://php.net/manual/en/language.types.string.php
更换
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'<td> <form action="del_prod.php" method="post">input type="checkbox" name="product_id" value="' . $row["product_id"] . '"></td>';
代码应该写成
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>";
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>";