Jump to content

Archived

This topic is now archived and is closed to further replies.

earl_dc10

refresh twice??

Recommended Posts

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 values

and a little off-topic, but can "this, " replace "window.document.main_table.comment_form"?

Thanks!

Share this post


Link to post
Share on other sites
[!--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 values

and 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 form

echo "

<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 worked

echo "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

Share this post


Link to post
Share on other sites
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 form

Refresh page due to POST

Display the current posts

Insert 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 form

Refresh due to POST

Insert the data

Display the current posts.

Hope that makes sense.

Share this post


Link to post
Share on other sites
[!--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 form

Refresh page due to POST

Display the current posts

Insert 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 form

Refresh due to POST

Insert the data

Display 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!

Share this post


Link to post
Share on other sites
[!--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

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.