我「完成」了我的評論系統,但仍有一個問題。 我寫註釋,然後重新加載該頁面後,再評論被貼再次.. 香港專業教育學院現在GOOGLE了2〜小時,不能找到一些幫助在重新加載頁面後提交模塊
代碼:
<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 at 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 is 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 INTO 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 a comment with 30 or more and 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 * from topmovies.comments ORDER BY 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
}
?>
有誰看到有一個錯誤是什麼錯誤? 我嘗試了1件事,但它不顯示回聲「添加評論!」
我可以做<腳本類型= 「文本/ JavaScript的」> window.location.reload();但我不能看到「評論加入!」回聲。我不想重定向到其他網站:/ – blaman
您可以嘗試在每次提交後立即更改發佈數據 – user1780932