forms - Block submit after reload page -


i "finished" commenting system 1 problem left. after write comment , reload page, comment gets posted again.. ive googled 2~ hours , cant find help

code:

<script type="text/javascript"> function toggle_comment(id) {     var e = document.getelementbyid(id);     if(e.style.display == 'block')       e.style.display = 'none';     else       e.style.display = 'block'; }  $(function() {   $(".submit").click(function() {      var comment = $("#comment").val();     var datastring = 'comment=' + comment;      if(comment=='')      {     alert('please enter @ least 30 characters');     return false      }     else     {     $.post("pages/comment.php", $("#postcommentform").serialize(),  function(data) {   });     }   }); });  $(function() {   $(".login").click(function() {      var username = $("#username").val();     var password = $("#password").val();     var datastring = 'username=' + username + '&password=' + password;      if(username=='' || password=='')      {     alert('login incorrect');     return false      }     else     {     $.post("pages/login.php", $("#postlogin").serialize(),  function(data) {   });     }   }); }); </script>  <a class="sitelinksblue" onclick="toggle_comment('commentfield');" style="font-family: verdana, geneva, sans-serif;font-size:12px;font-weight:bolder;">+ kommentar abgeben für englisch für anfänger</a> <br></br> <?php if(isset($_post['submitcomment']) && $_post['submitcomment']=="submit") {     if((checkcomment($_post['comment']) && strlen($_post['comment'])>=10 && strlen($_post['comment'])<=1500)) {  $sqlcmd = "insert topmovies.comments          (username,comment,date)          values          ('".mysql_real_escape_string($_session['user_username'])."','".mysql_real_escape_string($_post['comment']);."','".$sqlzeit."')"; $sqlqry = mysql_query($sqlcmd,$sqlhp); ?> <?php if (!$sqlqry) {     die('invalid query: ' . mysql_error()); }else { echo'comment added!'; }     }else{ echo'error! please enter comment 30 or more , 1500 or less characters';} } else { } ?> <div id="commentfield" style="display:none"> <?php if (isset($_session['user_username'])){     if($getadmin->status=='bann'){         echo $lang['bann'];         exit();     }else{ ?>     <form id="postcommentform" method="post" action="">         <p>dein name: <?php echo $_session['user_username']; ?></p>         <textarea class="textareacom" name="comment" id="comment" rows="5" cols="20" maxlength="1500" value=""></textarea><br />         <input name="submitcomment" id="submit" type="submit" class="submit" value="submit" />     </form> <?php     } }else{ ?> <form id="postlogin" action="" method="post"> <p style="font-weight:bolder;">um kommentare schreiben zu können musst du dich zuerst einloggen</p> <table>     <tr>         <td align="left"><font face="arial" color="#000000"><?php echo $lang['register_username']; ?></td>         <td align="left"><input type="text" name="username"/></td>     </tr>     <tr>         <td align="left"><font face="arial" color="#000000"><?php echo $lang['register_password']; ?></td>         <td align="left"><input type="password" name="password"/></td>     </tr>     <tr>         <td></td>         <td align="left"><input type="submit" id="login" value="login" name="submit" /></td>     </tr> </table> <a href="index.php?s=register"><?php echo $lang['login_register']; ?></a> | <a href="index.php?s=forgotpw"><?php echo $lang['forgot_pw']; ?></a> <br></br> </form> <?php } ?> </div> <?php $sql=mysql_query("select * topmovies.comments order date desc"); while($row=mysql_fetch_array($sql)) { $username=$row['username']; $comment=$row['comment']; $date=$row['date']; $name=$row['name']; ?>  <div id="comments" name="comments"> <div class="comments" style="padding-top:5px;">         <br>     <table width="746px" style="display:inline;" border="0" cellspacing="0" cellpadding="0">         <tr>         <td rowspan="4" valign="top" width="154px" style="padding-right:19px;"><img style="display: block; padding-top:10px;" src="http://img.movie4k.to/img/user_top.gif" height="8px"/>         <span class="test"><?php echo $username; ?><br />         <br />         <font size=1><?php echo date("d-m-y", strtotime($date))?></br>         <?php echo date("h:i", strtotime($date))?></font></span>         <img style="display: block; background-color: #afafaf; padding-left:10px; padding-right:10px;" src="http://img.movie4k.to/userpics/476090.gif" width=40 height=50/>         <img style="display: block;" src="http://img.movie4k.to/img/user_bottom.gif" height="8px"/></td>         <td colspan="2" valign="bottom" height="8px"><img style="display: block; padding-top:10px;" src="http://img.movie4k.to/img/comment_top2.gif" height="8px"/></td>         </tr>         <tr>         <td rowspan="2" width="522px" class="comment" valign="top" bgcolor="#e3e3e3" style="padding-left:10px; padding-right:17px;">         <?php echo $comment; ?>         </td>         <td width="85px" valign="top" bgcolor="#e3e3e3" style="font-size:19px;">         <div style="min-height:50px;"></div>         </td>         </tr>         <tr>         <td bgcolor="#e3e3e3" valign="bottom"></td>         </tr>         <tr>         <td colspan="2" valign="top" height="8px"><img style="display: block;" src="http://img.movie4k.to/img/comment_bottom2.gif" height="8px"/></td>         </tr>     </table> </div> </div> <br /> <?php } ?> 

does see there mistake wrong? tryed 1 thing, dont show echo "comment added!"

after user submits form, , after post data read php code, redir page. solve it.

if don't want that, compare post others see if has same content, close time-stamp, , same user. wouldn't recommend though.


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -