When sending comments C/o header("Location: I would like okazatsya not on the top of the page, and in the place where I sent this comment. How to do it?

I have a long list of movies. If I want to leave a comment after sending me throws in the beginning of the page. And I have to scroll the entire list to see where I left comments. Is it possible to make to be redirected to the form in which I left my comments using header("Location:../det.php");
echo '<form name="formaniz8" action="shablon/polzkomment.php" method="post" style=margin-top:8px;>
<table class=komet><tr><td class=komet1><textarea type="text" id="'.$idfilm.'" class="mess_fil7" name="mess_name" placeholder="Your comment"></textarea>
<input type="hidden" name="idfilm" value="'.$idfilm.'">
</td></tr></table>
</form>';

include("bd.php");
session_start();
 mysqli_query($bd, "SET NAMES utf8 COLLATE utf8_unicode_ci is a");
if(isset($_SESSION['id']))
{

 if (isset($_POST['mess_name'])) { $mess=$_POST['mess_name']; if ($mess ==") { unset($mess);} }
 //put user-entered password in a variable $password if it is empty, then destroy the variable

 if (empty($mess)) //if the user did not enter a username or password, then issue an error and stop
{

header("Location:../det.php");
exit;
}

$ids=$_SESSION['id'];




 $filter = array("<script>", "<SCRIPT>", "</SCRIPT>", "</script>", "alert", "<h" "<H", "<B", "<b", "style", "STYLE", "color", "COLOR", "width", "WIDTH", "height", "HEIGHT", "?>", "<?", "<?php");
$mess2=str_replace ($filter, "!", $mess);



 $rr = mysqli_query($bd, "SELECT id FROM komment ORDER BY id DESC ");
$rf=mysqli_fetch_array($rr);
$hh=$rf['id']+1;


$id=$_POST['idfilm'];


 $result=mysqli_prepare($bd, "INSERT INTO komment (`id`,`idfilm`,`idpolz`,`filmkom`,`data`) 
VALUES(?,?,?,?,NOW())");
 mysqli_stmt_bind_param($result, 'iiis', $hh, $id, $ids, $mess2 ); 
mysqli_stmt_execute($result);

}
 header("Location:../det.php");
April 7th 20 at 11:05
1 answer
April 7th 20 at 11:07
Solution
send comments Ajax.
or make a page anchor, and was redirected at him.
Ajax I have already done General chat and private messages. And this is the usual comments, there should be people to speak to and just shares his opinion about the context of one review. How to put an anchor and redirect to it? There is a very simple example kakoynit? or a link to it? - bernhard_Remp commented on April 7th 20 at 11:10
@bernhard_Remp, emmmm..... what is the relationship between Ajax and the communication between people? it's just one of the ways to send/receive data.

about the anchor can Google, you can start with htmlbook.ru/samhtml/yakorya - Pierre_Howell commented on April 7th 20 at 11:13
@Pierre_Howellto impede communication to not clog up a comments content does not need negotiations, they're not needed, there should be only one opinion from one user, and freely you can talk in General chat for him and did at Ajax. - bernhard_Remp commented on April 7th 20 at 11:16
@bernhard_Remp, ord: Ajax to litter the comments possible, and restart impossible.
yourself believe in it or simple have a vague idea about Ajax? - Pierre_Howell commented on April 7th 20 at 11:19
@Pierre_Howell, I can understand if the user is free to communicate in the comments about the film, it would have been no comments on the movie and just chat. And so he has to wait until the page is reloaded to open comments on the movie and then write something, and it is time-consuming, unlike the General chat.
As I can't razbiratsya in Ajax if I have General chat and personal messages on it? Here is an example:
function send()
{
 //Read message from input field with id mess_to_add
 var mess=$("#mess_to_send").val();

 // Send paltry
$.ajax({
 type: "POST",
 url: "shablon/add_mess.php",
data:"mess="+mess,

 // Print what is returned to PHP
 success: function(html)
{
 //If all is successfully loaded message
load_messes();
 //Clear the form input messages
$("#mess_to_send").val(");
}
});
}




 //Function to retrieve
 load_messes function()
{
$.ajax({
 type: "POST",
 url: "shablon/load_messes.php",
 data: "req=ok",
 // Print what is returned to PHP
 success: function(html)
{
 //Clear the form input
$("#messages").empty();
 //Print what was returned to us php
$("#messages").append(html);
 //Scrollable block down(if there are many messages)
 var chat_scroll = $('.mes');
chat_scroll.scrollTop(chat_scroll.prop('scrollHeight'));
}
});
}
 setInterval(load_messes,3000);

One JS code adds to the database a message displays with the other dB - bernhard_Remp commented on April 7th 20 at 11:22
@Pierre_Howellme how to make right variable in the header:
header("Location:../det.php#.$id.");
or let's say I have a form:
<textarea type="text" id="'.$idfilm.'" class="mess_fil7" name="mess_name" placeholder="Your comment"></textarea>

You need this id using the header to navigate, and it is in the hidden variable. - bernhard_Remp commented on April 7th 20 at 11:25
@bernhard_Remp, so you want to prevent people spamming and complicate their lives, but want to help? Well then, either send comments on moderation or block form in a couple of minutes. - Brennan commented on April 7th 20 at 11:28
@bernhard_Remp, do so
header("Location: /det.php#{$idfilm}");
exit;

Page perezagruzite, and the browser hash #anchor will scroll it to the element with id="anchor". textarea with id=$idfilm you have already there:
< textarea type="text" id="'.$idfilm.'" class="mess_fil7" name="mess_name" placeholder="Your comment">

And header("Location: /det.php#{$id}"); the page should scroll to the comment with id=$id, if it is an HTML element with that id.
$id, as I understand from the structure of your database, the id of the specific comment.

In Location it is better to use an absolute url here is a link to RFC 7231, with an anchor - you can see how the page moves to the element with id='section-7.1.2' hash #section-7.1.2 in the url.
But the translation of this section of the RFC:
spoiler
Specification of HTTP/1.1 requires you to specify absolute URI as argument to " Location: including the scheme, hostname and absolute path, although some clients are able to accept a relative URI.
- buster_Pfeffer77 commented on April 7th 20 at 11:31
@buster_Pfeffer77Why and c $id and $idfilm does not work (maybe the fact that they're in the spoiler closed, click on comments and list of comments reveals) I even made even easier: with the film itself via the id tag of his find, and he finds it stupid in the beginning of the page throws me after sending the comment. Although I have in the bottom of the site id I've redirected he works and sends me where to go after posting. - bernhard_Remp commented on April 7th 20 at 11:34
@buster_Pfeffer77all figured out. Thank you very much) - bernhard_Remp commented on April 7th 20 at 11:37

Find more questions by tags PHP