duangan6731 2014-01-06 16:52
浏览 17
已采纳

Mysql DB无法正确更新

I'm sure im missing something very simple I have run mysql update scripts many times but this one wont work and I cant understand why. I'm calling data from a DB into a ckeditor text box when the update button is clicked this script runs I get success messages but the DB doesn't update what am I missing???

session_start();
include ("mysql-connect.php");
include ("check-login.php");
if(isset($_POST['editblogbody'])){
      if($_POST['editblogbody'] != "" && $_POST['editblogtitle'] != "" && $_POST['blog_id'] != ""){
          $title = $_POST['editblogtitle'];
          $body = $_POST['editblogbody'];
          $bid = $_POST['blog_id'];
          $sql = mysql_query("UPDATE blogs SET title='$title', body='$body' WHERE id='$bid'")or die (mysql_error());    
          echo '<img src="../_Images/round_success.png" alt="Success" width="31" height="30" />Success 1';  
          exit();            
      }
      else{
          echo '<img src="../_Images/round_success.png" alt="Success" width="31" height="30" />Success 2';  
          exit();
      }
}
else{
    echo '<img src="../_Images/round_error.png" alt="Error" width="31" height="30" /> &nbsp; Opps something went wrong. Please Try again.'; 
    exit();
}   

The script thats post the form

$('#editblog').on('submit', function (e) {
    e.preventDefault();
    $('input[type=submit]', this).attr('disabled', 'disabled');
    var blogTitle = $("#editblogtitle").val();
    var blogText = CKEDITOR.instances['editblogbody'].getData();
    var url = "../_Scripts/edit-blog.php";
    if (!blogTitle) {
        $('input[type=submit]', this).removeAttr('disabled');
        $("#blogeditreply").html('<img src="../_Images/round_error.png" alt="Error" width="31" height="30" /> &nbsp; Please type a Title.').show().fadeOut(6000);
        return false;
    } else if (!blogText) {
        $('input[type=submit]', this).removeAttr('disabled');
        $("#blogeditreply").html('<img src="../_Images/round_error.png" alt="Error" width="31" height="30" /> &nbsp; Please type in your Blog.').show().fadeOut(6000);
        return false;
    } else {
        $("#blogFormProcessGif").show();
        for (instance in CKEDITOR.instances) {
            CKEDITOR.instances['blogbody'].updateElement();
        }
        $.post(url, $('#editblog').serialize(), function (data) {
            $("#jqueryReply").html(data).show().fadeOut(6000);
            $("#blogFormProcessGif").hide();
            $.modal.close();
        });
    }
});

connection loos like so

define('HOSTNAME','#'); 
define('DB_USERNAME','#'); 
define('DB_PASSWORD','#');
define('DATABASE','#'); 
$link = mysql_connect(constant('HOSTNAME'), constant('DB_USERNAME'), constant('DB_PASSWORD')) or die("Database connection error, please check!"); mysql_select_db(constant('DATABASE'), $link) or die("Connection to the defined database not possible, please check!");

I can echo out all the varibles fine so all the info is there

Thanks

  • 写回答

2条回答 默认 最新

  • doudou890510 2014-01-06 17:44
    关注

    I missed something very simple sorry everyone :(

    $('#editblog').on('submit', function (e) {
        e.preventDefault();
        $('input[type=submit]', this).attr('disabled', 'disabled');
        var blogTitle = $("#editblogtitle").val();
        var blogText = CKEDITOR.instances['editblogbody'].getData();
        var url = "../_Scripts/edit-blog.php";
        if (!blogTitle) {
            $('input[type=submit]', this).removeAttr('disabled');
            $("#blogeditreply").html('<img src="../_Images/round_error.png" alt="Error" width="31" height="30" /> &nbsp; Please type a Title.').show().fadeOut(6000);
            return false;
        } else if (!blogText) {
            $('input[type=submit]', this).removeAttr('disabled');
            $("#blogeditreply").html('<img src="../_Images/round_error.png" alt="Error" width="31" height="30" /> &nbsp; Please type in your Blog.').show().fadeOut(6000);
            return false;
        } else {
            $("#blogFormProcessGif").show();
            for (instance in CKEDITOR.instances) {
    ////////////////////////////////////////////////////////////////////////
    //////////Forgot to change the editor instance here/////////////////////
                CKEDITOR.instances['blogbody'].updateElement();
    ////////////////////////////////////////////////////////////////////////
            }
            $.post(url, $('#editblog').serialize(), function (data) {
                $("#jqueryReply").html(data).show().fadeOut(6000);
                $("#blogFormProcessGif").hide();
                $.modal.close();
            });
        }
    });
    

    Sorry put a comment in the code. I forgot to change the ckeditor instance at the bottom of the script

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度