Dataprocessor: Warning: sqlsrv_query()

I’m running into an issue with my custom update php scripts below:
I’m using this sample as a model: dhtmlx.com/docs/products/dhtmlxG … nding.html

[code]

<?php //code below is simplified - in real app you will want to have some kins session based autorization and input value checking error_reporting(E_ALL ^ E_NOTICE); //include db connection settings require_once("../config.php"); require_once("../../db_sqlsrv.php"); $conn = sqlsrv_connect($serverName,$connectionInfo); function sqlsrv_insert_id() { $res = sqlsrv_query($conn,"SELECT @@identity AS id"); if ($row = sqlsrv_fetch_array($res, SQLSRV_FETCH_ASSOC)) { $id = $row["id"]; } //$id = $conn->lastInsertId('workWeek'); return $id; } function add_row(){ global $newId; $sql = "INSERT INTO workWeek(reportID,csiDivision,division,company,description) VALUES ('".$_GET["reportID"]."', '".$_GET["Division"]."', '".$_GET["CSI"]."', '".$_GET["Company"]."', '".$_GET["Description"]."')"; $res = sqlsrv_query($conn,$sql); //set value to use in response $newId = sqlsrv_insert_id(); return "insert"; } function update_row(){ $sql = "UPDATE workWeek SET reportID='".$_GET["reportID"]."', csiDivision='".$_GET["Division"]."', division= '".$_GET["CSI"]."', company= '".$_GET["Company"]."', description='".$_GET["Description"]."' WHERE id=".$_GET["gr_id"]; $res = sqlsrv_query($conn,$sql); alert($_GET['reportID']); return "update"; } function delete_row(){ $d_sql = "DELETE FROM workWeek WHERE id=".$_GET["gr_id"]; $resDel = sqlsrv_query($conn,$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"?>');

$mode = $_GET[“!nativeeditor_status”]; //get request mode
$rowId = $_GET[“gr_id”]; //id or row which was updated
$newId = $_GET[“gr_id”]; //will be used for insert operation

switch($mode){
case “inserted”:
//row adding request
$action = add_row();
break;
case “deleted”:
//row deleting request
$action = delete_row();
break;
default:
//row updating request
$action = update_row();
break;
}
//output update results
echo “”;
echo “”;
echo “”;
?>[/code]

The grid reads from another php page, which works fine, the updates aren’t working. I get this error: “Warning: sqlsrv_query() expects parameter 1 to be resource, null given”

I tested the connection $conn and it works just fine. Any help will be GREATLY appreciated. My app looks great, I just can’t save data.

Javascript for my grid:

[code]var workThisGrid = tabBody.attachGrid();
workThisGrid.enableMultiselect(true);
workThisGrid.enableMultiline(true);
workThisGrid.setColumnHidden(0,true);
workThisGrid.setColumnIds(‘reportID,Division,CSI,Company,Description’);
workThisGrid.setHeader(‘reportID,Division,CSI,Company,Description’);
workThisGrid.setInitWidths(‘5,75,160,125,*’);
console.log(‘Setting Work This Grid to Edit Mode.’);
workThisGrid.setColTypes(‘ro,combo,combo,ed,txt’);
workThisGrid.setColAlign(‘left,left,left,left,left’);
workThisGrid.setColSorting(‘int,str,str,str,str’);
workThisGrid.init();
combo = workThisGrid.getColumnCombo(2);
combo.enableFilteringMode(true);
combo.loadXML(comboXML);
workThisGrid.loadXML(url,function(){
tabBody.progressOff();
});

	var workThisDP = new dataProcessor('./codebase/connector/db/crud/updateWorkThis.php');
		workThisDP.enableDataNames(true);
		workThisDP.setUpdateMode('row');
		workThisDP.init(workThisGrid);
		
		workThisDP.defineAction('invalid',function(response){
			var message = response.getAttribute(response);
			dhtmlx.alert(message);
			return false;
		});
		workThisDP.defineAction('error',function(response){
			var message = response.getAttribute(response);
			dhtmlx.alert(message);
			return true;
		});[/code]

I’m attaching a demo if that helps.
wcrDemo.zip (755 KB)

I think you need to have

global $conn;

in all functions, that are using this variable. Currently $conn is defined on global level, so it is not visible for code inside of functions.

That worked thanks!