Kind of a newbie in using PHP/Ajax/SQL.
I am currently working in a small project where in we're asked to create a Facebook-esque website using the languages above. I am trying to create pages wherein the user can view the individual posts and the comments in each post. The user can also post comments on the same page. I also have a database to store the different details needed for the project (posts, user details, comments, etc.)
The data acquired from the page displaying the posts is passed through a GET method. There is also an ajax function for inserting the comment data into my database. The problem is, every time I try to insert the data into the database (through AJAX), the following error appears:
Notice: Undefined index: blog_title in C:\xampp\htdocs\postpage.php on line 24
I also noticed that the data I passed through the GET method disappears when I try to call the AJAX function. What can I do to solve the error?
Post data is acquired through here(line 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 Function:
<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>
Thank you in advance!