earl_dc10 Posted March 20, 2006 Share Posted March 20, 2006 I have a comments system on my site, it displays the 10 most recent comments and you can add a comment via a form underneath it. When I go to insert a comment, the page refreshes with nothing, then if you refresh the page a second time, it appears, there is nothing WRONG with that, it's actually exactly how it should execute, Im just wondering if there's an alternative without having a referring page, here's my code[code]<form name="comment_form" class="comment_form" action="<?php echo $self;?>" method="POST">Name <input type="text" name="name_comment_form" size="7"><br><textarea name="entry_comment_form" rows="2" cols="18" wrap="virtual"> </textarea><br><input type="submit" name="comment_form_sub" value="Input><?php$name_comment_form = $_POST['name_comment_form'];$entry_comment_form = $_POST['entry_comment_form'];$insert = "INSERT INTO $table VALUES ('$name_comment_form', '$entry_comment_form', '$num_comment')";$insert_query = mysql_query($insert, $link) or die("Couldn't insert comment ".mysql_error() );[/code]I have tried this, I may be in the right direction, but not sure....[code]<form name="comment_form" class="comment_form" action="<?php echo $self;?>" method="POST">Name <input type="text" name="name_comment_form" size="7"><br><textarea name="entry_comment_form" rows="2" cols="18" wrap="virtual"> </textarea><br><input type="submit" name="comment_form_sub" value="Input OnClick="<?php $name_comment_form = "window.document.main_table.comment_form.name_comment_form.value"; $entry_comment_form = "window.document.main_table.comment_form.name_comment_form.value"; // same insert query[/code]whenever I push submit on that code, only the "-" is entered that goes after the name, but once I refresh the page, it is then entered, on a new post, and if I load the page without submitting anything, the "window.document......" javascript stuff is entered into the valuesand a little off-topic, but can "this, " replace "window.document.main_table.comment_form"?Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/5324-refresh-twice/ Share on other sites More sharing options...
TEENFRONT Posted March 20, 2006 Share Posted March 20, 2006 [!--quoteo(post=356568:date=Mar 19 2006, 10:25 PM:name=earl_dc10)--][div class=\'quotetop\']QUOTE(earl_dc10 @ Mar 19 2006, 10:25 PM) [snapback]356568[/snapback][/div][div class=\'quotemain\'][!--quotec--]I have a comments system on my site, it displays the 10 most recent comments and you can add a comment via a form underneath it. When I go to insert a comment, the page refreshes with nothing, then if you refresh the page a second time, it appears, there is nothing WRONG with that, it's actually exactly how it should execute, Im just wondering if there's an alternative without having a referring page, here's my code[code]<form name="comment_form" class="comment_form" action="<?php echo $self;?>" method="POST">Name <input type="text" name="name_comment_form" size="7"><br><textarea name="entry_comment_form" rows="2" cols="18" wrap="virtual"> </textarea><br><input type="submit" name="comment_form_sub" value="Input><?php$name_comment_form = $_POST['name_comment_form'];$entry_comment_form = $_POST['entry_comment_form'];$insert = "INSERT INTO $table VALUES ('$name_comment_form', '$entry_comment_form', '$num_comment')";$insert_query = mysql_query($insert, $link) or die("Couldn't insert comment ".mysql_error() );[/code]I have tried this, I may be in the right direction, but not sure....[code]<form name="comment_form" class="comment_form" action="<?php echo $self;?>" method="POST">Name <input type="text" name="name_comment_form" size="7"><br><textarea name="entry_comment_form" rows="2" cols="18" wrap="virtual"> </textarea><br><input type="submit" name="comment_form_sub" value="Input OnClick="<?php $name_comment_form = "window.document.main_table.comment_form.name_comment_form.value"; $entry_comment_form = "window.document.main_table.comment_form.name_comment_form.value"; // same insert query[/code]whenever I push submit on that code, only the "-" is entered that goes after the name, but once I refresh the page, it is then entered, on a new post, and if I load the page without submitting anything, the "window.document......" javascript stuff is entered into the valuesand a little off-topic, but can "this, " replace "window.document.main_table.comment_form"?Thanks![/quote]i think your over complicating a simple script lol, have a look at this..<?if (!isset($comment_form_sub)) { // if the form has NOT been submitted, display the formecho "<form name=\"comment_form\" class=\"comment_form\" action=\"$self\" method=\"POST\">Name <input type=\"text\" name=\"name_comment_form\" size=\"7\\"><br><textarea name="entry_comment_form\" rows=\"2\" cols=\"18\" wrap=\"virtual\"> </textarea><br><input type=\"submit\" name=\"comment_form_sub\" value=\"Input\">";$name_comment_form = $_POST['name_comment_form'];$entry_comment_form = $_POST['entry_comment_form'];$comment_form_sub = $_POST['comment_form_sub'];}else { // if the form WAS submitted, do the funky dance.$insert = "INSERT INTO $table VALUES ('$name_comment_form', '$entry_comment_form', '$num_comment')";$insert_query = mysql_query($insert, $link) or die("Couldn't insert comment ".mysql_error() );if ($insert_query) { // checks to see if isert_query workedecho "Your comment was added!"; // display message} else // if insert did not work{ echo "oops, your comment was not added!"; // show message} // end if} // end if?>the usual - untested, lemmie know if theres bugs, after all it is 630 in the monring lol Quote Link to comment https://forums.phpfreaks.com/topic/5324-refresh-twice/#findComment-18979 Share on other sites More sharing options...
lessthanthree Posted March 20, 2006 Share Posted March 20, 2006 Yup,Another thing to check, although obvious, often escapes some people.If the code that inserts data into the database appears in your code AFTER you have printed out the comments / posts then it will obviously need the second refresh as the process is like below:Submit the formRefresh page due to POSTDisplay the current postsInsert the data.You can clearly see that it can't display a post that has not been inserted despite the fact that you have refreshed the page and submitted the form. Obviously then, when the page is refreshed a second time, you can see the data that was inserted on the first refresh. Therefore make sure your process is:Submit the formRefresh due to POSTInsert the dataDisplay the current posts.Hope that makes sense. Quote Link to comment https://forums.phpfreaks.com/topic/5324-refresh-twice/#findComment-18999 Share on other sites More sharing options...
earl_dc10 Posted March 20, 2006 Author Share Posted March 20, 2006 [!--quoteo(post=356615:date=Mar 20 2006, 06:30 AM:name=lessthanthree)--][div class=\'quotetop\']QUOTE(lessthanthree @ Mar 20 2006, 06:30 AM) [snapback]356615[/snapback][/div][div class=\'quotemain\'][!--quotec--]Yup,Another thing to check, although obvious, often escapes some people.If the code that inserts data into the database appears in your code AFTER you have printed out the comments / posts then it will obviously need the second refresh as the process is like below:Submit the formRefresh page due to POSTDisplay the current postsInsert the data.You can clearly see that it can't display a post that has not been inserted despite the fact that you have refreshed the page and submitted the form. Obviously then, when the page is refreshed a second time, you can see the data that was inserted on the first refresh. Therefore make sure your process is:Submit the formRefresh due to POSTInsert the dataDisplay the current posts.Hope that makes sense.[/quote]haha, yeah, I guess that puts me in my place ;) I guess I should've noted where in the script I was placing it! Thanks for your inputs! Quote Link to comment https://forums.phpfreaks.com/topic/5324-refresh-twice/#findComment-19143 Share on other sites More sharing options...
xtiancjs Posted March 21, 2006 Share Posted March 21, 2006 [!--quoteo(post=356762:date=Mar 20 2006, 03:57 PM:name=earl_dc10)--][div class=\'quotetop\']QUOTE(earl_dc10 @ Mar 20 2006, 03:57 PM) [snapback]356762[/snapback][/div][div class=\'quotemain\'][!--quotec--]haha, yeah, I guess that puts me in my place ;) I guess I should've noted where in the script I was placing it! Thanks for your inputs![/quote]Hi, I had exaclty the same problem, except everything worked great in firefox mac and but ie win needed a second refresh, xtian Quote Link to comment https://forums.phpfreaks.com/topic/5324-refresh-twice/#findComment-19212 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.