Hi all,
I have the grid , it need to add new row and update the data. Now, the grid can add new row, but it cannot save the data to database.
Could you anyone to help.
Thank you.
grid:
Add row
myDataProcessor = new dataProcessor(“lib/update_admin.php”);
//lock feed url;
myDataProcessor.setTransactionMode(“POST”, true);
//set mode as send-all-by-post;
myDataProcessor.setUpdateMode(“off”);
//disable auto-update;
myDataProcessor.init(dhxGrid);
update_admin.php
<?php require_once('config.php'); require_once('config_dp.php'); global $res,$row_num; $row = "SELECT * from www_user where userid"; $row_num = mysql_query ($row); $row_num = $row_num + 1; function add_row($rowId){ global $newId; $sql = "INSERT INTO www_user(userid,username,password,email,active,fullaccess) VALUES ('".$row_num."', '".addslashes($_POST[$rowId."_c0"])."', '".addslashes($_POST[$rowId."_c1"])."', '".addslashes($_POST[$rowId."_c2"])."', '".addslashes($_POST[$rowId."_c3"])."', '".addslashes($_POST[$rowId."_c4"])."')"; $res = mysql_query($sql); //set value to use in response $newId = mysql_insert_id(); return "insert"; } function update_row($rowId){ $sql = "UPDATE www_user SET userid ='".$row_num."', username= '".addslashes($_POST[$rowId."_c0"])."', password= '".addslashes($_POST[$rowId."_c1"])."', email= '".addslashes($_POST[$rowId."_c2"])."', active= '".addslashes($_POST[$rowId."_c3"])."', fullaccess= '".addslashes($_POST[$rowId."_c4"])."', WHERE userid=".rowId; $res = mysql_query($sql); return "update"; } //function delete_row($rowId){ // // $d_sql = "DELETE FROM samples_grid WHERE book_id=".$rowId; // $resDel = mysql_query($d_sql); // return "delete"; //} //include XML Header (as response will be in xml format) header("Content-type: text/xml"); //encoding may differ in your case echo('<?xml version="1.0" encoding="iso-8859-1"?>');//output update results
echo “”;
$ids = explode(“,”,$_POST[“ids”]);
//for each row
for ($i=0; $i < sizeof($ids); $i++) {
$rowId = $ids[$i]; //id or row which was updated
$newId = $rowId; //will be used for insert operation
$mode = $POST[$rowId."!nativeeditor_status"]; //get request mode
switch($mode){
case "inserted":
//row adding request
$action = add_row($rowId);
break;
case "deleted":
//row deleting request
$action = delete_row($rowId);
break;
default:
//row updating request
$action = update_row($rowId);
break;
}
echo "<action type='".$action."' sid='".$rowId."' tid='".$newId."'/>";
}
echo “”;
?>