2014-01-23 104 views
0

我想从我的数据库中获取数据以显示在文本框或textarea中,以便可以轻松编辑它,随时可以提交到数据库。出于某种原因,数据显示,但不在textarea中,因此不能被编辑。这可能是一个语法问题。谁能帮忙?谢谢。在HTML文本区域显示数据库数据(PHP,MySQL)

我的代码是:

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>"; 
} 

回答

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>"; 
} 
+0

+1甚至没有注意到... – jeroen

+0

它也最好的做法是使用XML/HTML属性双引号。 –

+0

谢谢。不能相信我错过了这一点。在那里,我认为这是更多。 – NewToThis

0

您的数据可能包含打破HTML,像<>字符。

你应该使用htmlspecialchars()逃脱你的数据:

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

谢谢。也将包括这个:) – NewToThis

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> 
+0

我认为这应该工作... – RS16