Ich habe ein Kommentar-System auf meinem Blog hinzugefügt, das Problem ist, dass ich keinen Kommentar in die Datenbank einfügen kann, denke ich, weil es nicht die Post-ID von erhalten kann der aktuelle Blog Aus comments.php werden die Daten an post_comments.php übergeben. Wie kann ich die Post-ID auf dem Ajax-Teil (unter dem Skript-Tag) übergeben? Das ist das erste Mal, dass ich Ajax benutze, also bin ich nicht wirklich gut damit. Jede Hilfe wird sehr geschätztWie bekomme ich die aktuelle Seite ID in einem Kommentar-System mit AJAX
comments.php:
<form method='post' action="" onsubmit="return post();">
<textarea id="comment" placeholder="Write Your Comment Here....."></textarea>
<br>
<input type="text" id="username" placeholder="Your Name">
<br>
<input type="submit" value="Post Comment">
</form>
<div id="all_comments">
<?php
$host="localhost";
$username="root";
$password="";
$databasename="comments";
$connect=mysql_connect($host,$username,$password);
$db=mysql_select_db($databasename);
$comm = mysql_query("select name,comment,post_time from comments order by post_time desc");
while($row=mysql_fetch_array($comm))
{
$name=$row['name'];
$comment=$row['comment'];
$time=$row['post_time'];
?>
<div class="comment_div">
<p class="name">Posted By:<?php echo $name;?></p>
<p class="comment"><?php echo $comment;?></p>
<p class="time"><?php echo $time;?></p>
</div>
<?php
}
?>
</div>
post_comments.php
<?php
$host="localhost";
$username="root";
$password="";
$databasename="comments";
$connect=mysql_connect($host,$username,$password);
$db=mysql_select_db($databasename);
if(isset($_POST['user_comm']) && isset($_POST['user_name']))
{
$comment=$_POST['user_comm'];
$name=$_POST['user_name'];
$insert=mysql_query("insert into comments values('','$name','$comment',CURRENT_TIMESTAMP)");
$select=mysql_query("select name,comment,post_time from comments where name='$name' and comment='$comment' ");
if($row=mysql_fetch_array($select))
{
$name=$row['name'];
$comment=$row['comment'];
$time=$row['post_time'];
?>
<div class="comment_div">
<p class="name">Posted By:<?php echo $name;?></p>
<p class="comment"><?php echo $comment;?></p>
<p class="time"><?php echo $time;?></p>
</div>
<?php
}
exit;
}
?>
Sorry, ich vergaß fälschlicherweise name = "post_id" in verstecktes Feld zu setzen –
danke:) ist dies perfekt – grasig
Sie sind herzlich willkommen. –