Jump to content


Photo

refresh twice??


  • Please log in to reply
4 replies to this topic

#1 earl_dc10

earl_dc10
  • Members
  • PipPipPip
  • Advanced Member
  • 71 posts

Posted 20 March 2006 - 03:25 AM

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

<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() );

I have tried this, I may be in the right direction, but not sure....

<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

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!

got a problem? Google helps many of those in need

#2 TEENFRONT

TEENFRONT
  • Members
  • PipPipPip
  • Advanced Member
  • 338 posts

Posted 20 March 2006 - 06:50 AM

[!--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) View Post[/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

<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() );

I have tried this, I may be in the right direction, but not sure....

<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

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
Teenfront.co.uk : Free Teen Chat -  FunkySmileys.co.uk : MSN Smileys -  ArcadeMonkey.co.uk : Free Flash Games
8Baller.co.uk : Free Multiplayer Pool [url=http://8Baller.co.uk]

#3 lessthanthree

lessthanthree
  • Members
  • PipPipPip
  • Advanced Member
  • 85 posts
  • LocationUK

Posted 20 March 2006 - 11:30 AM

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.
call me a safe bet, i'm betting i'm not

#4 earl_dc10

earl_dc10
  • Members
  • PipPipPip
  • Advanced Member
  • 71 posts

Posted 20 March 2006 - 08:57 PM

[!--quoteo(post=356615:date=Mar 20 2006, 06:30 AM:name=lessthanthree)--][div class=\'quotetop\']QUOTE(lessthanthree @ Mar 20 2006, 06:30 AM) View Post[/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!
got a problem? Google helps many of those in need

#5 xtiancjs

xtiancjs
  • Members
  • PipPipPip
  • Advanced Member
  • 47 posts

Posted 21 March 2006 - 02:50 AM

[!--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) View Post[/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




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users