【问题标题】:Form submitting in php用php提交表单
【发布时间】:2013-06-17 12:22:09
【问题描述】:

---编辑--- 我创建了一个文本框区域,用户可以在其中输入一些数据,

基本上当我按下提交按钮时,它应该保存输入的数据。这是完整的代码,我无法修复它。 :/

用户条目未更新。

    <?php
if ( $act == "htmlprofile" ) {


 ?>


    <div class="contentcontainer">
  <div class="contentmboardheaderarea"><img src="images/header.png" />
<div style=”word-wrap: break-word”><div class="contentheadertext"><?php echo "$hlang2"; ?></div></div></div>
  <div class="contentheading">
      <form id="htmlform" name="htmlform" method="post" action="options.php?act=htmlsubmit">
    <div class="contentheading4">
    <?php echo "$olang15"; ?></div>
</div>
    <div class="contentmboardlistarea2"><textarea id="htmlprofile" name="htmlprofile" cols="33" rows="10"><?php echo $qry2[htmlprofile];?>
 </textarea></div></form>
  <div class="contentbuttonarea">
    <div class="contentbutton1" onClick="document.location.href = 'profile.php?act=index'";><?php echo "$glang3"; ?></div>
    <div class="contentbutton2" onClick="document.forms['htmlform'].submit();"><?php echo "$glang21"; ?></div>
    <div class="contentbutton3"></div>
    <div class="contentbutton4"></div>
    <div class="contentbutton5" onClick="document.location.href = 'help.php#htmlprofile'";><?php echo "$glang5"; ?></div>
  </div>
</div>

<?php
}
?>


<?php
if ( $act == "htmlsubmit" ) {

$save ='Profile updated successfully';  
$query4 = "UPDATE members SET htmlprofile = '$htmlprofile' WHERE username = '$myuser'";
mysql_query($query4);
?>

【问题讨论】:

  • 我只是想知道你的submit 按钮在哪里(?)
  • 它可能没有提交数据,因为 POST 操作要转到 options.php。
  • @Fred - 我假设它被document.forms['htmlform'].submit()调用
  • 当用户到达页面时,&lt;div class="contentheadertext"&gt; 里面到底是什么(我看到了&lt;?php echo "$hlang2"; ?&gt;
  • @andrewsi 我也是这么想的,但是没看到有其他JS支持。

标签: php forms textarea


【解决方案1】:

textarea中没有value属性你必须输入&lt;textarea&gt;text&lt;/textarea&gt;之间的内容

参考tag_textarea

It should be like this
 <textarea  id="htmlprofile" name="htmlprofile" cols="33" rows="16" >
 <?php echo $qry2[htmlprofile]; ?>
 </textarea>

也参考这个答案which-value-will-be-sent-by-textarea-and-why

【讨论】:

    【解决方案2】:

    您的 div contentheadertext 不包含在 &lt;form&gt;&lt;/form&gt; 中,因此如果您在那里有输入,它们将不会包含在表单提交中。

    要解决此问题,请将开头的 &lt;form&gt; 标记移到更高处,以便包含所有输入。

    【讨论】:

      【解决方案3】:

      提交工作正常。但是您没有定义发布数据的变量。并且 textareas 没有“价值”。当你不需要在你的回声中固定字符串时,不要使用“

      尝试以下方法:

      <textarea id="htmlprofile" name="htmlprofile" cols="33" rows="16"><?php echo htmlspecialchars($_POST['htmlprofile']); ?></textarea>
      

      【讨论】:

      • 我已经提到textarea你的回答和我的有什么不同??
      • profile.php 中有一个名为“$content”的变量如何提交
      • 当我开始测试输入我的答案时,没有其他答案。我还提到了一些额外的事情。
      【解决方案4】:

      如果您尝试在 HTML 中使用 php 变量,只需 echo $myvariable 即可;那里不需要报价。但是,如果您尝试回显字符串,请使用引号,就像 echo 'mystring' 。

      此外,当您尝试将某些值作为表单提交的一部分传递时,所需的值应位于标签之间

      如果您想在文本区域内显示任何值,请记住它没有“值”属性。所以写这样的代码:要显示的值

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2011-10-03
        • 2017-02-11
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多