gpt4 book ai didi

php - 表单不向mysql表插入信息?

转载 作者:行者123 更新时间:2023-11-29 14:03:34 25 4
gpt4 key购买 nike

您好,我的论坛评论表单出现问题。基本上我试图允许用户阅读用户帖子并对其发表评论,表单数据应该插入到 mysql 中。

我需要插入的值是comment_id(用户的 session ID)和post_id(他们评论的帖子的ID)以及他们输入的内容。

由于某种原因,这没有被插入到 mysql 中,并且出现了我回显的成功消息,没有任何错误。有人可以告诉我哪里出了问题吗?

谢谢

<?php
$page_title = "Read Post";
include('includes/header.php');
include ('includes/mod_login/login_form2.php'); ?>

<?php
confirm_logged_in();



if (isset ($_GET['post'])) {
$forum_id = $_GET['post'];
}

?>

<?php include('includes/copyrightbar.php'); ?>
<?
$read_forum_set = read_forum_set();
while ($forum = mysql_fetch_array($read_forum_set)) {?>
<div class="modtitle">
<div class="modtitle-text"><?php echo "{$forum['display_name']}"; ?>'s Forum Post</div>
<? } ?>
</div>

<div class="modcontent57">


<br /><br /><br/><br/>

<div class="forum">
<div class="forum-pic"><?php echo "<img src=\"data/photos/{$_SESSION['user_id']}/_default.jpg\" width=\"100\" height=\"100\" border=\"0\" align=\"right\" class=\"img-with-border-forum\" />";?>
</div>

<div class="message-links">
<strong><a href="forum.php"><< Back to Forum</a>
</div>
<br /><br /><br/><br/>
<?php

$datesent1 = $forum['date_sent']; ?>

<?php
$read_forum_set = read_forum_set();
while ($forum = mysql_fetch_array($read_forum_set)) {
$prof_photo = "data/photos/{$forum['user_id']}/_default.jpg";

$result = mysql_query("UPDATE ptb_forum SET ptb_forum.read_forum='1' WHERE ptb_forum.id='$forum'")
or die(mysql_error());

?>
<div class="message-date">
<?php echo "".date('D M jS, Y - g:ia', strtotime($forum['date_sent'])).""; ?></div>



<div class="img-with-border-frm-read"><?php echo "<a href=\"profile.php?id={$forum['from_user_id']}\"><img width=\"60px\" height=\"60px\" src=\"{$prof_photo}\"></a><br />"; ?></div>



<?php echo "<div class=\"forum-content2\"><div class=\"forum_subject\"><strong>Subject:</strong></div><div class=\"forum_subject2\"><i>{$forum['title']}</i></div><div class=\"forum_body\"><strong>Post:<br/></strong></br ><i>{$forum['content']}</i></div></div>";?>



<?php
// check if the review form has been sent
if(isset($_POST['forum_comment']))
{
$content = $_POST['forum_comment'];
//We remove slashes depending on the configuration
if(get_magic_quotes_gpc())
{
$content = stripslashes($content);
}
//We check if all the fields are filled
if($_POST['forum_comment']!='')
{


{
$sql = "INSERT INTO ptb_forum_comments (comment_id, post_id, content) VALUES (NULL, '".$_SESSION['user_id']."', '".$profile_id."', '".$content."');";
mysql_query($sql, $connection);

echo "<div class=\"infobox-profile4\"><strong>Thank You</strong> - Your review has been sent for approval.</div>";
} }
}

?>


<?php if(isset ($_SESSION['user_id'])) { ?>



<div class="forum-comment-box">
<form action="<?php $_SERVER['PHP_SELF'] ?>" method="post">
<textarea name="forum_comment" id="forum_comment" style="resize:none; height:100px; width:543px;"></textarea><input type="submit" name="send_button" id="send_button" style="float:right; margin-right:30px; text-align:center;" value="Reply to {$message['display_name']}" /></form></div>

<? } } ?>


</div>
</div>



<?php include('includes/footer.php'); ?>
</div>

最佳答案

这里缺少一些表名称:

$sql = "INSERT INTO ptb_forum_comments (comment_id, post_id, content) VALUES (NULL, '".$_SESSION['user_id']."', '".$profile_id."', '".$content."');";

如您所见,您有 3 个表名称和 4 个值。

关于php - 表单不向mysql表插入信息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14714903/

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