0

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)

Community
  • 1
  • 1
e.vejar
  • 43
  • 1
  • 9

1 Answers1

0

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!

ruffin
  • 16,507
  • 9
  • 88
  • 138