2011-06-06 185 views
0

PHP已經有一段時間了,所以請原諒我的無知。我有這個網頁:PHP發佈變量問題

<?php 
mysql_connect ("localhost", "user", "pass"); 
mysql_select_db ("expiration"); 

if (isset ($_REQUEST['new_expire']) && $_REQUEST['new_expire'] != "") { 
    $insert_query = "INSERT INTO files (path, expires) VALUES ('"; 
    $insert_query .= $_REQUEST['new_path']; 
    $insert_query .= "', '"; 
    $insert_query .= $_REQUEST['new_expire']; 
    $insert_query .= "');"; 
    mysql_query ($insert_query); 
} 
?> 
<html> 
<head></head> 
<body> 
    <?php echo print_r $_REQUEST; ?> 
    <form action="index.php" method="POST"> 
     <p>Add New Expiration</p> 
     <table> 
      <tr> 
       <td align="right"> 
        Select File: 
       </td> 
       <td> 
        <select id="new_path"> 
         <?php $options = buildOptions(); echo $options; ?> 
        </select> 
       </td> 
      </tr> 
      <tr> 
       <td align="right"> 
        MySQL Expire Time: 
       </td> 
       <td> 
        <input type="text" id="new_expire" /> 
       </td> 
      </tr> 
      <tr> 
       <td></td> 
       <td> 
        <input type="submit" value="Save" /> 
       </td> 
      </tr> 
     </table> 
    </form> 
</body> 
</html> 
<?php 
mysql_close(); 
?> 

當我加載頁面時,print_r的結果是一個空的數組。當我提交表單時,它仍然是空的。數據庫中沒有新記錄。有任何想法嗎?

+1

輸入元素' print_r()'默認已經直接輸出結果,所以不需要添加'echo',因爲它只是吐出print_r返回的值,它是TRUE。當然,因爲PHP的標誌是一致的,所以如果你使用'print_r(true)',它將返回該轉儲,然後你的回聲就可以工作。 – 2011-06-06 18:22:09

回答

9

改變這一切,你必須要idname的場合,例如:

<input type="text" id="new_expire" /> - ><input type="text" name="new_expire" />

_REQUEST(無論是_POST_GET)只是從與name

+0

好的一個沒有注意到它 – dynamic 2011-06-06 17:42:16

+0

是的,這就是答案,謝謝。 – Nik 2011-06-06 17:43:09

+0

沒問題@Nik :-D – Neal 2011-06-06 17:43:48