在HTML文本区域中显示数据库数据(PHP,MySQL)

时间:2014-01-23 23:29:36

标签: php mysql forms textbox

我正在尝试从我的数据库中获取数据以显示在文本框或文本区域中,以便可以轻松编辑,准备提交到数据库。由于某种原因,数据显示但不在textarea中,因此无法编辑。这可能是语法问题。有人可以帮忙吗?谢谢。

我的代码是:

while($row = mysqli_fetch_array($result))
{
  echo "<div id='item'>";
  echo "<form action='updateproductmain.php' method='post'";
  echo "<textarea rows='5' cols='20' name='quote' wrap='physical'>" . $row['product_name'] . "</textarea>";
  echo "<input type='submit' value='Submit'>";
  echo "</form>";
  echo "</div>";
}

3 个答案:

答案 0 :(得分:2)

在表单标记上缺少结束>

while($row = mysqli_fetch_array($result))
{
   echo "<div id='item'>";
   echo "<form action='updateproductmain.php' method='post'>";
   echo "<textarea rows='5' cols='20' name='quote' wrap='physical'>" . $row['product_name'] . "</textarea>";
   echo "<input type='submit' value='Submit'>";
   echo "</form>";
   echo "</div>";
}

答案 1 :(得分:0)

您的数据可能包含破坏html的字符,例如<>

您应该使用htmlspecialchars()转义数据:

echo "<textarea rows='5' cols='20' name='quote' wrap='physical'>" . htmlspecialchars($row['product_name']) . "</textarea>";

答案 2 :(得分:0)

<form action="" method="post" enctype="multipart/form-data">
                <table style="border:2px solid black;" >
                <tr><td> <input type="text" name="id" value="<?php echo $edit;  ?>" style="display:none;"></td><tr></tr>
                <tr><td> <input type="text" name="firstname" value="<?php echo $firstname;  ?>"></td><tr></tr>
                <td> <input type="text" name="lastname" value="<?php echo $lastname; ?>"></td><tr></tr>
                <td> <input type="text" name="contact" value="<?php echo $contact; ?>"></td><tr></tr>
                <td> <textarea name="address"  rows="" cols="" value="<?php echo $address; ?>"></textarea></td><tr></tr>
                <tr><td><input type="file" name="image" ></td></tr>
                <tr><td><input type="text" name="image" style="display:none;" value="<?php echo $image?>"></td><tr></tr>
                <td> <input type="submit" name="update" value="update"></td>
                </table>
                </form>