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
的結果是一個空的數組。當我提交表單時,它仍然是空的。數據庫中沒有新記錄。有任何想法嗎?
輸入元素' print_r()'默認已經直接輸出結果,所以不需要添加'echo',因爲它只是吐出print_r返回的值,它是TRUE。當然,因爲PHP的標誌是一致的,所以如果你使用'print_r(true)',它將返回該轉儲,然後你的回聲就可以工作。 – 2011-06-06 18:22:09