【发布时间】:2020-04-16 00:42:36
【问题描述】:
有点像使用 PHP/Ajax/SQL 的新手。
我目前在一个小项目中工作,我们被要求使用上述语言创建一个 Facebook 风格的网站。我正在尝试创建页面,用户可以在其中查看每个帖子中的单个帖子和 cmets。用户还可以在同一页面上发布 cmets。我还有一个数据库来存储项目所需的不同详细信息(帖子、用户详细信息、cmets 等)
从显示帖子的页面获取的数据通过 GET 方法传递。还有一个 ajax 函数用于将评论数据插入我的数据库。问题是,每次我尝试将数据插入数据库(通过AJAX)时,都会出现以下错误:
Notice: Undefined index: blog_title in C:\xampp\htdocs\postpage.php on line 24
我还注意到,当我尝试调用 AJAX 函数时,我通过 GET 方法传递的数据消失了。我该怎么做才能解决这个错误?
通过这里获取post数据(第24行):
$blog_title = $_GET['blog_title'];
HTML:
<!DOCTYPE html>
<html>
<head>
<title><?=$blog_title?></title>
</head>
<body>
<div class = "details">
<h2><?=$row['title']?></h2>
<h3>Published by: <a link href = "<?=$location?>"><?=$row['author_name']?></a></h3>
<h4>Date Posted: <?=$row['date']?> at <?=$row['time']?></h4>
</div>
<br>
<p>
<?=$row['content']?>
</p><br><br>
<div class = "commentarea">
<form>
<label>Commenting as: <?=$my_username?></label><br>
<textarea rows = "10" cols = "20" id = "comment" required></textarea>
<button name = "comment" id = "post" onclick="Comment($('#comment').val(), <?=$my_username?>, <?=$blog_title?>)">Submit Comment</button>
</form>
<div>
AJAX 功能:
<script src = "js/jquery.js"></script>
<script>
function Comment(comment, username, title){
//alert(search + " " + filter);
$.ajax({
method:"POST",
url:"comment.php",
data:{
"comment":comment,
"commenter_name":username,
"commented_post":title,
},
dataType = "json",
success: function(result){
alert("Comment posted.");
$("#record").html(result);
}
});
}
</script>
提前谢谢你!
【问题讨论】:
标签: php html ajax database get