2014-01-23 134 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