php
  • forms
  • 2010-10-23 71 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> 
    
    相關問題