Repeat the questions replied to this POST. a result of imitating Baidu POST bar is to click a POST title on the POST list page to go to the POST homepage. after the value is queried in the database, click it to display the Post author and title content. I also added a reply function to insert the submitted reply data into a table. this is because the submission of the reply is completed on this page. after the submission of the reply action is completed, the POST title and the author content are not received and the POST value cannot be queried in the database. Therefore, an error is reported. so how can I keep querying the title and author of a post? If an if statement is made to determine whether the database content is queried normally if the POST value is received, what should be done if the database content is not received?
Reply to discussion (solution)
On the post list page, click a post title to go to the Post homepage.
This post homepage displays the post and reply content, and has a form for reply, which is submitted to this page.
Because there is a Post id passed in from the Post list page when you enter the Post homepage, the form for reply also needs to contain the Post id
In fact, the truth is very simple. if you don't bring the post id, you won't be able to know who the reply is.
The workflow of the Post homepage is:
Check whether the form is submitted
If yes, the system will reply to the database
Reads content and replies from the table based on the input Post id, and displays the content
On the post list page, click a post title to go to the Post homepage.
This post homepage displays the post and reply content, and has a form for reply, which is submitted to this page.
Because there is a Post id passed in from the Post list page when you enter the Post homepage, the form for reply also needs to contain the Post id
In fact, the truth is very simple. if you don't bring the post id, you won't be able to know who the reply is.
The workflow of the Post homepage is:
Check whether the form is submitted
If yes, the system will reply to the database
Reads content and replies from the table based on the input Post id, and displays the content
I understand what you said, but how can I handle the jump post value if I submit a reply on the post page? if I submit a reply, the post value will not be received on this page. how can I query and display it? the current page address is http: // localhost/tieba3.php? Id = 4 How can I make the address bar or id = 4 when I submit a reply?
Since the reply is submitted to this page, the form action does not need to be written.
In this way, the url parameter will not become
Complete Code
Post list page
Script
Window. onload = function (){
Var oIpt1 = document. getElementById ('ipt1 ');
Var oIpt2 = document. getElementById ('ipt2 ');
Var oIpt3 = document. getElementById ('ipt3 ');
Var oTxt1 = document. getElementById ('txt1 ');
Var oSub = document. getElementById ('sub ');
Var re =/^ (0 | 86 | 17951 )? (13 [0-9] | 15 [012356789] | 17 [678] | 18 [0-9] | 14 [57]) [0-9] {8} $ /;
OIpt1.onblur = onblurHandler;
OIpt2.onblur = onblurHandler;
OIpt3.onblur = onblurHandler;
Function onblurHandler (event ){
Var targetmediaevent.tar get;
Var oV1 = target. value;
If (oV1 = ''){
Target. style. border = '1px solid Red ';
}
Else {
Target. style. border = '';
}
}
}
Script
Include "cookie. php ";
Echo $ _ COOKIE ['username'];
?>
Include 'function. php ';
Header ('content-type: text/html; charset = utf-8 ;');
$ Pdo = new PDO ("mysql: host = localhost; dbname = t1", "root ","");
$ Stmt = $ pdo-> prepare ("select * from tieba ");
$ Stmt-> execute ();
$ Res = $ stmt-> fetchall ();
$ Rows = count ($ res); // The total number of rows.
$ Pagesize = 8;
If ($ rows = 0 ){
$ Pagenum = 0;
} Else {
$ Pagenum = ceil ($ rows/$ pagesize); // divided into several pages
}
If (isset ($ _ GET ['Page']) {
$ Page = $ _ GET ['Page'];
If (empty ($ page) | $ page <0 |! Is_numeric ($ page )){
$ Page = 1;
} Else {
$ Page = intval ($ page );
}
} Else {
$ Page = 1;
}
If ($ page> $ pagenum ){
$ Page = $ pagenum;
}
$ Startnum = ($ page-1) * $ pagesize;
$ Display_page = 5;
$ Query = "SELECT * FROM tieba LIMIT $ startnum, $ pagesize ";
$ Stmt2 = $ pdo-> prepare ($ query );
$ Stmt2-> execute ();
$ Res2 = $ stmt2-> fetchall (PDO: FETCH_ASSOC );
Foreach ($ res2 as $ v ){
Echo'
'. $ V ['title'].'';
}
?>
Fenye ();
?>
Post homepage
Include "cookie. php ";
?>
If (isset ($ _ GET ['title']) {
Echo $ _ GET ['title'];
$ Pdo = new PDO ("mysql: host = localhost; dbname = t1", "root ","");
$ Title = $ _ GET ['title'];
$ Stmt = $ pdo-> prepare ("select id, title, type, name, num, site, content from tieba where title =? ");
$ Stmt-> execute (array ($ title ));
$ Res3 = $ stmt-> fetchall (PDO: FETCH_ASSOC );
Foreach ($ res3 as $ v ){
Echo ''. $ v ['num'].'';
$ Id1 = $ v ['id'];
}
} Else {
Echo $ id1;
}
?>
$ Id2 = $ v ['id'];
$ Pdo = new PDO ("mysql: host = localhost; dbname = t1", "root ","");
$ Stmt = $ pdo-> prepare ("select id, name, content from reply where reid =? ");
$ Stmt-> execute (array ($ id2 ));
$ Res1 = $ stmt-> fetchall (PDO: FETCH_ASSOC );
Foreach ($ res1 as $ v2 ){
Echo $ v2 ['name'];
}
?>
Since the reply is submitted to this page, the form action does not need to be written.
In this way, the url parameter will not become
Thank you, moderator.