所以我很累,一直在嘗試這個好幾個小時,現在仍然無法找到它爲什麼不起作用。瞭解我,這可能是我在某個地方犯的一個愚蠢的錯誤。 Anyhoo,我有一個表格,我需要能夠提交,隨後輸入的文本被插入到數據庫中。然而,每當我按下提交,它只是回到主頁面,並沒有插入任何東西。代碼在這裏:提交表單到數據庫不能正常工作
//New Memory
<?php
if ($x == 'new') {
?>
<a href="pensieve_elizabeth.php"><- Back</a>
<center>
<table width="400" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>
<form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="post">
<input type="hidden" name="submitted" value="submitted" />
<p><b>Add Memory </b></p>
<p>Title:<br>
<input class="textfield" name="title" maxlength="55" style="width:325px;">
<br>
Memory: <br>
<textarea class="textfield" name="entry" value="entry" id="entry" cols="30" rows="10" style="width:325px;"></textarea><br>
<input type="submit" value=" Submit " />
<input type="checkbox" name="private" value="1"> Private
<p>What thread does the memory belong to? (optional):<textarea class="textfield" name="links" rows="1" style="width:325px;"></textarea><br />
</form>
</td>
</tr>
</table>
</center>
<?php
if(isset($_POST['submitted'])) {
$title = trim(addslashes(strip_tags(htmlspecialchars($_POST['title']))));
$entry = trim(addslashes(strip_tags(htmlspecialchars($_POST['entry']))));
$private = $_POST['private'];
$links = $_POST['links'];
if (empty($title)) message("Please give the memory a title.");
if (empty($entry)) message("Your memory is empty.");
mysql_query("INSERT INTO pensieve SET uid = '$userID', subject = '$title', memory = '$entry', dateline = '".date()."', private = '$private', links = '$links'") or die(mysql_error());
message("You have successfully submitted this memory to your pensieve!","/pensieve_elizabeth.php");
}
}
?>
爲什麼回聲之前不動你isset塊? – funerr 2012-07-28 20:32:18
啊是的,我之前有過,它沒有工作,所以我複製另一個腳本移動它:/ – Elizabeth 2012-07-28 20:33:39
$ PHP_SELF只是指當前的網址 – Elizabeth 2012-07-28 20:34:03