Search code examples
phphtmlformsinputtextbox

Text box that is editable


I have a text box that is populated by a form on my website. This text box is also editable and I'm having issues displaying the full text onto the text box from the form the user fills out. So, for example, if a user enters "hello there" and submits it, the text box will only display "hello" and not the full message.

my code:

 $sql = "SELECT * FROM form";

  $result = $conn->query($sql);
  if ($result->num_rows > 0) {
   // output data of each row


   echo "<table>
   <tr>
   <th>Title</th>
   <th>Description</th>
   <th></th>
   <th></th>
   <th></th>
   </tr>";
   while($row = $result->fetch_assoc()) {
   echo "<form action=findGroup.php method=post>";
   echo "<tr>";
   echo "<td>" ."<input type=text name=name value=" . $row['form_name'] . " </td>";
   echo "<td>" ."<input type=text name=description value=" . $row['form_description'] . " </td>";
   echo "<td>" ."<input type=hidden name=hidden value=" . $row['form_id'] . " </td>";
   echo "<td>" ."<input type=submit name=update value=update" . " </td>";
   echo "<td>" ."<input type=submit name=delete value=delete" . " </td>";
   echo "</tr>";
   echo "</form>";
  }
  echo "</table>";
  }

Solution

  • The main problem is you do not enclose your values is apostrophes (''), so it only picks up the first word it sees.

    Fix :

       echo "<form action=findGroup.php method=post>";
       echo "<tr>";
       echo "<td>" ."<input type=text name=name value='" . $row['form_name'] . "'/> </td>";
       echo "<td>" ."<input type=text name=description value='" . $row['form_description'] . "'/> </td>";
       echo "<td>" ."<input type=hidden name=hidden value='" . $row['form_id'] . "'/></td>";
       echo "<td>" ."<input type=submit name=update value='update" . "'</> </td>";
       echo "<td>" ."<input type=submit name=delete value='delete" . "'/></td>";
       echo "</tr>";
       echo "</form>";