使用Ajax-PDO的cleditor内容不保存或删除

时间:2013-05-29 01:51:57

标签: mysql ajax pdo insert

| R-edit | 我正在使用ajax + PDO在cleditor中保存/删除内容,ajax调用内容但无法将其保存到db中,当我删除内容时(已插入内容) phpadmin)它说它不能删除但已经它已经确实...另一个问题是我需要它的内容向用户显示管理员插入,而不是每个人。我做了这个关系,但也许我做错了这是我的代码:

我编辑这个是因为我现在只有ajax..right有问题现在我可以保存或删除但是ajax无法工作。

如果我插入动作action="response.php",请使用此页面转到响应页面...我需要ajax调用....请帮助

page.php中的

<form id="FormSubmit" method="post" action="">
<input type='hidden' id="id_paciente" name="id_paciente" type="text" value='<?php echo $id_paciente ?>' />
<input type='hidden' id="id_doctor" name="id_doctor" type="text" value='<?php echo $id_doctor ?>' />
<textarea id="hconsulta" name="hconsulta" rows="10" cols="50"></textarea><br>
<input class="submit" value="Guardar Consulta" type="submit" />
</form>
    <ul id="responds">
    <?
      $sql = 'SELECT DIAGNOSTICO.*,PACIENTES.* FROM DIAGNOSTICO,PACIENTES WHERE PACIENTES.id_paciente=DIAGNOSTICO.id_paciente';
      $result = $conn->query($sql);
      while($row = $result->fetch(PDO::FETCH_ASSOC)) {

      echo '<li id="item_'.$row["id_paciente"].'">';
      echo '<div class="del_wrapper"><a href="#" class="del_button" id="del-'.$row["id_paciente"].'">';
      echo '<img src="../images/icon_del.gif" border="0" />';
      echo '</a></div>';
      echo $row["diagnosticos"].'</li>';
    }
    ?>
    </ul>

ajax调用脚本

<script type="text/javascript">
<![CDATA[
$(document).ready(function(){
    $("#FormSubmit").submit(function(){

        // Remove any existing errors
        $(".error").remove();

        var id_paciente = $("#id_paciente").val();
        var id_doctor = $("#id_doctor").val();
        var hconsulta = $("#hconsulta").val();

        // Validate Message
        if (hconsulta == '') {
            check = false;
            $('#hconsulta').after('<div class="error">* Message is required!</div>');
        }
        else if (message.length < 6) {
            check = false;
            $('#hconsulta').after('<div class="error">* Message is too short!</div>');
        }

        // If validation is successful
        if (check == true) {
            $.ajax({
                type: "POST",
                url: "response.php",
                data: $("#FormSubmit").serialize(),
                dataType: "json",
                success: function(response){

                    if (!response.mailSuccess && !response.databaseSuccess)
                    {
                        $('#hconsulta').after('<div class="error">* Something went very wrong! Please try again!</div>');
                    }                                       
                } 
            });
        }
        return false;
    });
});
]]>
</script>

和response.php

 <?php
include_once("config.php");
        try{
    $statement = $conn->prepare("INSERT INTO DIAGNOSTICO (id_paciente, id_doctor, hconsulta) VALUES (?, ?, ?)");

    if ($statement->execute(array($_POST['id_paciente'], $_POST['id_doctor'], $_POST['hconsulta'])));
        $dbSuccess = true;

} catch (Exception $e) {
    $return['databaseException'] = $e->getMessage();
}
   $dbh = null;   
?>

最诚挚的问候!

1 个答案:

答案 0 :(得分:0)

您已将语句设置为显示错误,即使它删除了记录也是如此 使用下面的代码

   $count=$conn->prepare("delete from DIAGNOSTICO 
                           WHERE id_diagnostico=$idToDelete")
    $count->bindParam("$idToDelete",$id_diagnostico,PDO::PARAM_INT);
    $delete=$count->execute();
    if (!$delete)
           {    
            header('HTTP/1.1 500 Could not delete record!');
            exit();
            }
       $dbh = null;    
    }
    else
    {
        header('HTTP/1.1 500 Error occurred, Could not process request!');
        exit();
    }