gpt4 book ai didi

php - 向数据库提交表单不起作用

转载 作者:行者123 更新时间:2023-11-29 08:49:22 24 4
gpt4 key购买 nike

所以我累了,已经尝试了几个小时了,但仍然找不到为什么它不起作用。了解我,这可能是我在某个地方犯了一些愚蠢的错误。无论如何,我有一个需要能够提交的表单,然后输入的文本将被插入到数据库中。但是,每当我按下提交时,它只会返回主页并且不会插入任何内容。代码在这里:

//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");
}
}
?>

最佳答案

您的查询有误。

  mysql_query("INSERT INTO pensieve SET uid = '$userID', subject = '$title', memory = '$entry', dateline = '".date()."', private = '$private', links = '$links'") or die(mysql_error());

必须

mysql_query("INSERT INTO pensieve(uid, subject, memory, dateline, private, links) values('$userID', '$title', '$entry', '".date()."', '$private', '$links')") or die(mysql_error());

关于php - 向数据库提交表单不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11704411/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com