php
  • forms
  • 2010-10-23 72 views -1 likes 
    -1

    这里是我的代码:错误变量传递在PHP形式

    echo "<table class='forum'> 
    <tr> 
    <td class='forum'><b>Enter Response Here:</b></td> 
    </tr> 
    <form action='a_insert.php?id=" . $answerid . " method=post> 
    <tr class='forum'> 
    <td class='forum'><textarea rows='5' cols='80' name='cBody'></textarea></td> 
    </tr> 
    <tr class='forum'> 
    <td><input type='submit' value='submit'></td></tr> 
    </form></table><br><br>"; 
    

    它目前通过“cBody”,而不是$ answerid像我想它。我该如何解决?

    感谢大家的帮助。

    回答

    5

    当表单由POST发送时,您应该将该id添加为表单中的输入,而不是查询字符串的一部分。

    <input type="hidden" name="id" value="<?php echo $answerid; ?>" />

    +0

    完美,t这么多! – BigMike 2010-10-23 06:17:51

    0

    你在这里缺少一个右引号:

    <form action='a_insert.php?id=" . $answerid . " method=post> 
    

    它应该是:

    <form action='a_insert.php?id=" . $answerid . "' method=post> 
    

    然而,你应该使用这样的代码:

    <table class="forum"> 
    <tr> 
    <td class="forum"><b>Enter Response Here:</b></td> 
    </tr> 
    <form action="a_insert.php?id=<?php echo $answerid?>" method="post"> 
    <tr class="forum"> 
    <td class="forum"><textarea rows="5" cols="80" name="cBody"></textarea></td> 
    </tr> 
    <tr class="forum"> 
    <td><input type="submit" value="submit"></td></tr> 
    </form></table><br><br> 
    
    相关问题