The jquery query looks like this.
<script> function post(){ $.post("pages/comment.php?id=<?echo$row['id'];?>", { text<?echo$row['id'];?>: $("#text<?echo$row['id'];?>").val() }, function(data) { if(data != "ok"){ $("#error_error").html("<div class=\"alert alert-error\"><a class=\"close\" data-dismiss=\"alert\" href=\"#\">Γ</a>"+data+"</div>"); }else{ location.replace("/articles.php?id=<?echo$row['id'];?>"); } }); } </script>
File handler
require_once '../system/core.php'; $row = mysql_fetch_assoc(mysql_query("SELECT * FROM `articles` WHERE `id`='".$id."' AND `moderation`='1'")); $text=htmlspecialchars(trim($_POST['text'])); if (empty($text)) { echo 'ΠΠ΅ Π²Π²Π΅Π΄ΡΠ½ ΡΠ΅ΠΊΡΡ ΠΊΠΎΠΌΠΌΠ΅Π½ΡΠ°ΡΠΈΡ!'; exit; } if (mb_strlen($text) < 2 || mb_strlen($text) > 1000) { echo 'ΠΠ΅Π΄ΠΎΠΏΡΡΡΠΈΠΌΠ°Ρ Π΄Π»ΠΈΠ½Π° ΡΠ΅ΠΊΡΡΠ° ΠΊΠΎΠΌΠΌΠ΅Π½ΡΠ°ΡΠΈΡ'; exit; } //Π΅ΡΠ»ΠΈ Π½Π΅Ρ ΠΎΡΠΈΠ±ΠΎΠΊ - ΠΏΠΈΡΠ΅ΠΌ Π² Π±Π°Π·Ρ mysql_query("UPDATE `articles` SET `comments` = '".intval($row['comments']+1)."' WHERE `id` = '".$row['id']."'"); mysql_query("INSERT INTO `articles_comments` SET `id_user` = '".$user['id']."', `id_articles` = '".$row['id']."', `text` = '".mysql_real_escape_string($text)."', `time` = '".$realtime."'"); $rating_user = $user['rating']+0.05; if($user['rating']<$setup['rating'])mysql_query("UPDATE `users` SET `rating`='".$rating_user."' WHERE `id`='".$user['id']."'"); echo "ok";
The form
echo '<div id="error_error"></div>'; echo '<textarea id="text'.$row['id'].'" rows="5" placeholder="ΠΠ²Π΅Π΄ΠΈΡΠ΅ Π²Π°Ρ ΠΊΠΎΠΌΠΌΠ΅Π½ΡΠ°ΡΠΈΠΉ"></textarea> <input type="button" class="blue" value="ΠΠΎΠ±Π°Π²ΠΈΡΡ ΠΊΠΎΠΌΠΌΠ΅Π½ΡΠ°ΡΠΈΠΉ" onclick="post()"><br/>';
So, you need to somehow add the article ID to the post-request. On one page I have a certain number of articles. Each article has comments.