dpglo66848 2013-07-31 15:01
浏览 34
已采纳

ajax返回成功但mysql db没有更新

I have a javascript for loop that sends an array to an ajax page to update the mysql database.

I echo the result back to the original page and it echos as a success but when I check the db nothing has changed

my javascript for loop that sends the array

for(var m=0; m<array.length; m++){
    $.post("update_page_positions.php",{page_ref:array[m][0], ref:array[m][12], menu_pos:array[m][1], sub_menu_pos:array[m][2], top_menu:array[m][3], pagelink:array[m][4], indexpage:array[m][5], hidden:array[m][6], page_title:array[m][7], page_desc:array[m][8], page_keywords:array[m][9], page_name:array[m][10], deletedpage:array[m][11]},         
        function(data,status){  
            alert("data="+data+" status="+status);   
});                 

here is the php ajax page the updates the db

<?
    include("connect.php");     
    $ref = $_POST['ref'];
    $page_ref = $_POST['page_ref'];
    $menu_pos = $_POST['menu_pos'];
    $sub_menu_pos = $_POST['sub_menu_pos'];  
    $top_menu = $_POST['top_menu'];
    $indexpage = $_POST['indexpage'];       
    $page_name = $_POST['page_name'];    
    $page_title = $_POST['page_title'];
    $page_desc = $_POST['page_desc'];   
    $page_keywords = $_POST['page_keywords'];   
    $hidden = $_POST['hidden']; 
    $pagelink = $_POST['pagelink']; 
    $deletedpage = $_POST['deletedpage'];   

    $query = mysql_query("SELECT * FROM pages WHERE ref='$ref' AND page_ref='$page_ref'");

 if(mysql_num_rows($query)==0){
    mysql_query("INSERT INTO pages(page_ref, ref, page_name, menu_pos, sub_menu_pos, top_menu, link, indexpage) VALUES('$page_ref','$ref','$page_name','$menu_pos','$sub_menu_pos','$top_menu','$pagelink','$indexpage')");
}

 if($deletedpage=="1"){
        mysql_query("DELETE FROM pages WHERE ref='$ref' AND page_ref='$page_ref'");         
        mysql_query("DELETE FROM site_content WHERE ref='$ref' AND page_ref='$page_ref'");
 } 
 else{       
       if(mysql_query("UPDATE pages SET menu_pos='$menu_pos', sub_menu_pos='$sub_menu_pos', top_menu='$top_menu', indexpage='$indexpage', page_name='$page_name', page_title='$page_title', desc1='$page_desc', keywords_list='$page_keywords', hidden='$hidden', link='$pagelink' WHERE ref='$ref' AND page_ref='$page_ref'")){

        echo "updated!";
     } else{
        echo "error";           
      }

 }   
?>

the INSERT and DELETE functions are fine but the UPDATE returns a success statement but does not update the db.

Can anyone see what the problem is?

  • 写回答

2条回答 默认 最新

  • douciwang6819 2013-07-31 15:06
    关注

    Posted as an answer because the comment was too hard to read:

    Rather than echoing "updated", try echoing

    "UPDATE pages SET menu_pos='$menu_pos', sub_menu_pos='$sub_menu_pos', top_menu='$top_menu', indexpage='$indexpage', page_name='$page_name', page_title='$page_title', desc1='$page_desc', keywords_list='$page_keywords', hidden='$hidden', link='$pagelink' WHERE ref='$ref' AND page_ref='$page_ref'"
    

    (ie. the query you're trying to run).

    See if that gives you some clues.

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

报告相同问题?

悬赏问题

  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 unity第一人称射击小游戏,有demo,在原脚本的基础上进行修改以达到要求
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)