dongtuo2373 2011-12-11 06:10
浏览 75
已采纳

Jqgrid我无法将更改更新到数据库中

My jqgrid loads perfectly data, but when I want to commit changes on it, nothing happens on my database. I don't know exactly when happens the "enter key" event for saving the row, so I don't know where put this code:

jQuery("#lista").saveRow(id, function(){alert("changes saved")}, 'guardar_lista.php');

I already saw this example: JQgrid checkbox onclick update database but I'm very hard headed about how to use ajax for send the info (sorry, I'm a newbie).

Can you give me a code example of how to send the info with ajax? Here is my Editurl code:

    <?

    $dbhost="localhost";
    $dbuser="root";
    $dbpassword="";
    $database="db_proyecto";


    $db = mysql_connect($dbhost, $dbuser, $dbpassword) or die("Connection Error: " . mysql_error()); 
    mysql_select_db($database, $db);


    if($_POST['oper']=='edit'){
        $invid=$_POST['id'];
        $tax=$_POST['tax'];
        $note=$_POST['note'];
        $total=$_POST['total']; 
        $SQL="update invheader set note='"+$note+"' where invid="+$invid;
        mysql_query($SQL,$db);
}

Thank you in advance @ruffin! (Sorry for the delay, I was very busy)

  • 写回答

1条回答 默认 最新

  • dotelauv682684 2011-12-12 22:58
    关注

    Well, you're going to have to post a little more code for us to know for sure. Your grid should have a value for your editurl, which is the page that's going to process your updated data (iirc). Just to be clear, that url is where you'd insert your mysql_query jive.

    Note that you're either going to have jive coming in your $_GET or $_POST collection with the new values from the grid, with "_empty" for the id column if it's a new row (since it's not filled; this is a new row). (Yes, I realize you're updating, but just in case you add soon enough.)

    Eg... ("FORM" each time means it's coming from the $_POST array)

    FORM: PREFIX :: REV 
    FORM: FNAME :: Joe
    FORM: MNAME :: Frazier
    FORM: LNAME :: Test
    FORM: SUFFIX :: suffix
    FORM: oper :: add
    FORM: id :: _empty
    

    Decent code to review here: http://www.trirand.com/jqgridwiki/doku.php?id=wiki:inline_editing

    More on _empty and form editing here: http://www.trirand.com/jqgridwiki/doku.php?id=wiki:form_editing

    So we need your editurl, we need to know that the "php code for update data" is IN that page, and we probably should see what you've got on the page with the grid in full to give a SUPER WONDERFUL answer. ;^)

    You should probably also write up a dummy page at your editurl that iterates through all the values from your $_GET and $_POST collections and writes them to a file so that you can check what the grid is sending you -- and that you're getting anything at all. Also, please please PUH-lease use mysql_real_escape_string() around $name and at least an int check for $id!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 我的代码无法在vc++中运行呀,错误很多
  • ¥50 求一个win系统下运行的可自动抓取arm64架构deb安装包和其依赖包的软件。
  • ¥60 fail to initialize keyboard hotkeys through kernel.0000000000
  • ¥30 ppOCRLabel导出识别结果失败
  • ¥15 Centos7 / PETGEM
  • ¥15 csmar数据进行spss描述性统计分析
  • ¥15 各位请问平行检验趋势图这样要怎么调整?说标准差差异太大了
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
  • ¥15 wpf界面一直接收PLC给过来的信号,导致UI界面操作起来会卡顿
  • ¥15 init i2c:2 freq:100000[MAIXPY]: find ov2640[MAIXPY]: find ov sensor是main文件哪里有问题吗