可编辑的文本框

时间:2018-04-01 21:17:04

标签: php html forms input textbox

我的文本框由我网站上的表单填充。此文本框也是可编辑的,我在从用户填写的表单的文本框中显示全文时遇到问题。因此,例如,如果用户输入“hello there”并提交它,则文本框将仅显示“hello”而不显示完整消息。

我的代码:

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

2 个答案:

答案 0 :(得分:2)

  • 在html参数值
  • 中添加引号
  • 表单值
  • 中的转义引号
  • 以/&gt;
  • 结束&lt;输入

让你的线条看起来像:

echo "<td><input type=text name=name value='" . addslashes($row['form_name']) . "'/></td>";

其余部分类似。

答案 1 :(得分:1)

主要问题是你没有把你的值括起来是撇号(&#39;&#39;),所以它只会找到它看到的第一个单词。

修复:

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