0

I am trying to get data from my database to appear in a textbox or textarea so that it can be easily edited, ready to be submitted to the database. For some reason the data displays but not in a textarea, and therefore cant be edited. This could be a syntax issue. Can anyone help? Thank you.

My code is:

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 Answers 3

2

Missing the end > on your form tag:

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>";
}
Sign up to request clarification or add additional context in comments.

2 Comments

It's also best practice to use double quotes for XML / HTML attributes.
Thank you. Can't believe I missed that. There I was thinking it was something much more.
0

Your data probably contains characters that break the html, like < or >.

You should escape your data using htmlspecialchars():

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

1 Comment

Thank you. Will also include this :)
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>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.