php - 评论系统 jQuery/ajax php mysql

标签 php jquery mysql ajax comments

我目前正在开发一个评论系统,但我不知道如何修复这个错误.. 当我在文本区域中写入内容并按下提交时,什么也没有发生。 文件链接正确! 当我没有在文本区域中输入任何内容时,它会显示给定的错误。

这里是comment.php文件

<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 Give Valide Details');
     }
    else
    {
    $("#flash").show();
    $("#flash").fadeIn(400).html('<img src="ajax-loader.gif" align="absmiddle">&nbsp;<span class="loading">Loading Comment...</span>');
$.ajax({
        type: "POST",
  url: "index.php?s=comment",
   data: dataString,
  cache: false,
  success: function(html){

  $("#flash").hide();

  }
 });
}
return false;
    });



});
</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>
<?php
if($_POST) {
$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);
if (!$sqlQry) {
    die('Invalid query: ' . mysql_error());
}else { echo'Comment Added!';}
}
?>

<div id="commentfield" style="display:none">
    <form method="POST" action="#">
        <p>Dein Name: <?PHP echo $_SESSION['user_username']; ?></p>
        <textarea class="interfaceforms" name="comment" id="comment" rows="5" cols="20" maxlength="1555" value=""></textarea><br />
        <input type="submit" class="submit" value="Submit" />
    </form>
</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;">
        </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
}
?>

希望有人知道出了什么问题! 也许可以给我一些关于安全/更好性能等方面的建议。

最佳答案

您的错误可能由多种原因引起,但至少您的代码应该有一个 divid 名为 flash

 <div id='flash'>...</div>`

您的 HTML 部分没有这样的 div

关于php - 评论系统 jQuery/ajax php mysql,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18265490/

相关文章:

php - 使用 mysqli 计算行数并传递信息

在 Linux CentOS 中写入文件时出现 PHP 权限错误

java - 使用 JQuery 在 Javascript 中解析外部 JSON 文件(包含数组元素)

mysql - 如何在 MySQL 中以 root@localhost 权限运行?

php - 停止复制数据库中行数据的开头

php - 无法上传面临警告 : move_uploaded_file 的文件

javascript - 图像的响应式空白图像叠加

Javascript/Jquery 脚本因超时而终止

php - 在php中不使用while循环查看所有表字段值

php - 如何设置1 :many relationships in MySQL