gpt4 book ai didi

php - 不知道为什么帖子没有插入我的数据库

转载 作者:行者123 更新时间:2023-11-30 01:29:15 25 4
gpt4 key购买 nike

我已经检查了我能想到的所有内容,但无法弄清楚为什么我的代码会创建错误消息而不是插入到数据库中,我什至将 echo "
Select SQL = ".$sql2. “
”;在我的结果查询并得到以下数据之前...

Select SQL = INSERT INTO `posts`(post_topic, post_id, post_content, post_date, post_by)VALUES('3', '2', 'me too', '15/07/13 22:04:00', '1'
ERROR

检查值,一切正确,帖子加入的主题是 3,这是帖子表中的第二篇帖子,“我也是”是正确的帖子内容,数据良好, session user_id 是1、我一头雾水,这是页面的完整代码。

<?php
include 'core/init.php';
include 'includes/overall/header.php';

// Get value of id that sent from hidden field
$id=$_POST['id'];

// Find highest answer number.
$sql="SELECT MAX(post_id) AS Maxa_id FROM `posts` WHERE post_topic='$id'";
$result=mysql_query($sql);
$rows=mysql_fetch_array($result);

// add + 1 to highest answer number and keep it in variable name "$Max_id". if there no answer yet set it = 1
if ($rows) {
$Max_id = $rows['Maxa_id']+1;
}
else {
$Max_id = 1;
}

// get values that sent from form

$post_content=$_POST['post_content'];

$datetime=date("d/m/y H:i:s"); // create date and time

// Insert answer
$sql2="INSERT INTO `posts`(post_topic, post_id, post_content, post_date, post_by)VALUES('$id', '$Max_id', '$post_content', '$datetime', '" . $_SESSION['user_id'] . "'";
echo "<BR>Select SQL = ".$sql2."<BR>";
$result2=mysql_query($sql2);

if($result2){
echo "Successful<BR>";
echo "<a href='view_topic.php?topic_id=".$id."'>View your answer</a>";

// If added new answer, add value +1 in reply column

$sql3="UPDATE `topics` SET reply='$Max_id' WHERE topic_id='$id'";
echo "<BR>Select SQL = ".$sql3."<BR>";
$result3=mysql_query($sql3);
}
else {
echo "ERROR";
}

// Close connection
mysql_close();
?>
<?php include 'includes/overall/footer.php'; ?>

最佳答案

在 VALUES 语句的末尾,您缺少 ),目前只有“;”。

关于php - 不知道为什么帖子没有插入我的数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17656338/

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