Index: frontends/php/include/httptest.inc.php
===================================================================
--- frontends/php/include/httptest.inc.php	(revision 38884)
+++ frontends/php/include/httptest.inc.php	(working copy)
@@ -70,14 +70,14 @@
 			return false;
 		}
 
-		if(!$httpstep_data = DBfetch(DBselect('select httpstepid from httpstep where httptestid='.$httptestid.' and name='.zbx_dbstr($name)))){
+		if(!$httpstep_data = DBfetch(DBselect('select httpstepid from httpstep where httptestid='.zbx_dbstr($httptestid).' and name='.zbx_dbstr($name)))){
 
 			$httpstepid = get_dbid("httpstep","httpstepid");
 
 			if (!DBexecute('insert into httpstep'.
 				' (httpstepid, httptestid, name, no, url, timeout, posts, required, status_codes) '.
-				' values ('.$httpstepid.','.$httptestid.','.zbx_dbstr($name).','.$no.','.
-				zbx_dbstr($url).','.$timeout.','.
+				' values ('.$httpstepid.','.$httptestid.','.zbx_dbstr($name).','.zbx_dbstr($no).','.
+				zbx_dbstr($url).','.zbx_dbstr($timeout).','.
 				zbx_dbstr($posts).','.zbx_dbstr($required).','.zbx_dbstr($status_codes).')'
 				)) return false;
 		}
@@ -85,9 +85,9 @@
 			$httpstepid = $httpstep_data['httpstepid'];
 
 			if (!DBexecute('update httpstep set '.
-				' name='.zbx_dbstr($name).', no='.$no.', url='.zbx_dbstr($url).', timeout='.$timeout.','.
+				' name='.zbx_dbstr($name).', no='.zbx_dbstr($no).', url='.zbx_dbstr($url).', timeout='.zbx_dbstr($timeout).','.
 				' posts='.zbx_dbstr($posts).', required='.zbx_dbstr($required).', status_codes='.zbx_dbstr($status_codes).
-				' where httpstepid='.$httpstepid)) return false;
+				' where httpstepid='.zbx_dbstr($httpstepid))) return false;
 		}
 
 		$monitored_items = array(
@@ -114,12 +114,12 @@
 		foreach($monitored_items as $item){
 			$item_data = DBfetch(DBselect('select i.itemid,i.history,i.trends,i.delta,i.valuemapid '.
 				' from items i, httpstepitem hi '.
-				' where hi.httpstepid='.$httpstepid.' and hi.itemid=i.itemid '.
-				' and hi.type='.$item['httpstepitemtype']));
+				' where hi.httpstepid='.zbx_dbstr($httpstepid).' and hi.itemid=i.itemid '.
+				' and hi.type='.zbx_dbstr($item['httpstepitemtype'])));
 
 			if(!$item_data){
 				$item_data = DBfetch(DBselect('select i.itemid,i.history,i.trends,i.delta,i.valuemapid '.
-					' from items i where i.key_='.zbx_dbstr($item['key_']).' and i.hostid='.$hostid));
+					' from items i where i.key_='.zbx_dbstr($item['key_']).' and i.hostid='.zbx_dbstr($hostid)));
 			}
 
 			$item_args = array(
@@ -178,11 +178,11 @@
 
 			$httpstepitemid = get_dbid('httpstepitem', 'httpstepitemid');
 
-			DBexecute('delete from httpstepitem where itemid='.$itemid);
+			DBexecute('delete from httpstepitem where itemid='.zbx_dbstr($itemid));
 
 			if (!DBexecute('insert into httpstepitem'.
 				' (httpstepitemid, httpstepid, itemid, type) '.
-				' values ('.$httpstepitemid.','.$httpstepid.','.$itemid.','.$item['httpstepitemtype'].')'
+				' values ('.$httpstepitemid.','.zbx_dbstr($httpstepid).','.zbx_dbstr($itemid).','.zbx_dbstr($item['httpstepitemtype']).')'
 				)) return false;
 
 		}
@@ -206,7 +206,7 @@
 			$sql = 'SELECT t.httptestid'.
 					' FROM httptest t, applications a'.
 					' WHERE t.applicationid=a.applicationid'.
-						' AND a.hostid='.$hostid.
+						' AND a.hostid='.zbx_dbstr($hostid).
 						' AND t.name='.zbx_dbstr($name);
 			$t = DBfetch(DBselect($sql));
 			if((isset($httptestid) && $t && ($t['httptestid'] != $httptestid)) || ($t && !isset($httptestid))){
@@ -214,7 +214,7 @@
 			}
 
 
-			$sql = 'SELECT applicationid FROM applications WHERE name='.zbx_dbstr($application).' AND hostid='.$hostid;
+			$sql = 'SELECT applicationid FROM applications WHERE name='.zbx_dbstr($application).' AND hostid='.zbx_dbstr($hostid);
 			if($applicationid = DBfetch(DBselect($sql))){
 				$applicationid = $applicationid['applicationid'];
 			}
@@ -232,16 +232,16 @@
 				$sql = 'UPDATE httptest SET '.
 					' applicationid='.$applicationid.', '.
 					' name='.zbx_dbstr($name).', '.
-					' authentication='.$authentication.', '.
+					' authentication='.zbx_dbstr($authentication).', '.
 					' http_user='.zbx_dbstr($http_user).', '.
 					' http_password='.zbx_dbstr($http_password).', '.
-					' delay='.$delay.', '.
-					' status='.$status.', '.
+					' delay='.zbx_dbstr($delay).', '.
+					' status='.zbx_dbstr($status).', '.
 					' agent='.zbx_dbstr($agent).', '.
 					' macros='.zbx_dbstr($macros).', '.
 					' error='.zbx_dbstr('').', '.
 					' curstate='.HTTPTEST_STATE_UNKNOWN.
-				' WHERE httptestid='.$httptestid;
+				' WHERE httptestid='.zbx_dbstr($httptestid);
 				if(!DBexecute($sql)){
 					throw new Exception('DBerror');
 				}
@@ -253,11 +253,11 @@
 					'httptestid' => $httptestid,
 					'applicationid' => $applicationid,
 					'name' => zbx_dbstr($name),
-					'authentication' => $authentication,
+					'authentication' => zbx_dbstr($authentication),
 					'http_user' => zbx_dbstr($http_user),
 					'http_password' => zbx_dbstr($http_password),
-					'delay' => $delay,
-					'status' => $status,
+					'delay' => zbx_dbstr($delay),
+					'status' => zbx_dbstr($status),
 					'agent' => zbx_dbstr($agent),
 					'macros' => zbx_dbstr($macros),
 					'curstate' => HTTPTEST_STATE_UNKNOWN,
@@ -288,7 +288,7 @@
 			}
 
 /* clean unneeded steps */
-			$sql = 'SELECT httpstepid FROM httpstep WHERE httptestid='.$httptestid;
+			$sql = 'SELECT httpstepid FROM httpstep WHERE httptestid='.zbx_dbstr($httptestid);
 			$db_steps = DBselect($sql);
 			while($step_data = DBfetch($db_steps)){
 				if(!isset($httpstepids[$step_data['httpstepid']])){
@@ -314,12 +314,12 @@
 			foreach($monitored_items as $item){
 				$item_data = DBfetch(DBselect('select i.itemid,i.history,i.trends,i.delta,i.valuemapid '.
 					' from items i, httptestitem hi '.
-					' where hi.httptestid='.$httptestid.' and hi.itemid=i.itemid '.
-					' and hi.type='.$item['httptestitemtype']));
+					' where hi.httptestid='.zbx_dbstr($httptestid).' and hi.itemid=i.itemid '.
+					' and hi.type='.zbx_dbstr($item['httptestitemtype'])));
 
 				if(!$item_data){
 					$item_data = DBfetch(DBselect('select i.itemid,i.history,i.trends,i.delta,i.valuemapid '.
-						' from items i where i.key_='.zbx_dbstr($item['key_']).' and i.hostid='.$hostid));
+						' from items i where i.key_='.zbx_dbstr($item['key_']).' and i.hostid='.zbx_dbstr($hostid)));
 				}
 
 				$item_args = array(
@@ -378,10 +378,10 @@
 
 				$httptestitemid = get_dbid('httptestitem', 'httptestitemid');
 
-				DBexecute('delete from httptestitem where itemid='.$itemid);
+				DBexecute('delete from httptestitem where itemid='.zbx_dbstr($itemid));
 
 				if(!DBexecute('insert into httptestitem (httptestitemid, httptestid, itemid, type) '.
-					' values ('.$httptestitemid.','.$httptestid.','.$itemid.','.$item['httptestitemtype'].')')){
+					' values ('.$httptestitemid.','.zbx_dbstr($httptestid).','.zbx_dbstr($itemid).','.zbx_dbstr($item['httptestitemtype']).')')){
 					throw new Exception('DBerror');
 				}
 			}
@@ -415,7 +415,7 @@
 
 		$db_httpstepitems = DBselect('SELECT DISTINCT * FROM httpstepitem WHERE '.DBcondition('httpstepid',$httpstepids));
 		while($httpstepitem_data = DBfetch($db_httpstepitems)){
-			if(!DBexecute('DELETE FROM httpstepitem WHERE httpstepitemid='.$httpstepitem_data['httpstepitemid'])) return false;
+			if(!DBexecute('DELETE FROM httpstepitem WHERE httpstepitemid='.zbx_dbstr($httpstepitem_data['httpstepitemid']))) return false;
 			if(!delete_item($httpstepitem_data['itemid'])) return false;
 		}
 
@@ -427,7 +427,7 @@
 
 		$httptests = array();
 		foreach($httptestids as $id => $httptestid){
-			$httptests[$httptestid] =  DBfetch(DBselect('SELECT * FROM httptest WHERE httptestid='.$httptestid));
+			$httptests[$httptestid] =  DBfetch(DBselect('SELECT * FROM httptest WHERE httptestid='.zbx_dbstr($httptestid)));
 		}
 
 		$db_httpstep = DBselect('SELECT DISTINCT s.httpstepid '.
@@ -464,17 +464,17 @@
 	}
 
 	function activate_httptest($httptestid){
-		$r = DBexecute('UPDATE httptest SET status='.HTTPTEST_STATUS_ACTIVE.' WHERE httptestid='.$httptestid);
+		$r = DBexecute('UPDATE httptest SET status='.HTTPTEST_STATUS_ACTIVE.' WHERE httptestid='.zbx_dbstr($httptestid));
 
 		$itemids = array();
-		$sql = 'SELECT hti.itemid FROM httptestitem hti WHERE hti.httptestid='.$httptestid;
+		$sql = 'SELECT hti.itemid FROM httptestitem hti WHERE hti.httptestid='.zbx_dbstr($httptestid);
 		$items_db = DBselect($sql);
 		while($itemid = Dbfetch($items_db)){
 			$itemids[] = $itemid['itemid'];
 		}
 
 		$sql = 'SELECT hsi.itemid FROM httpstep hs, httpstepitem hsi WHERE '.
-			' hs.httptestid='.$httptestid.' AND hs.httpstepid=hsi.httpstepid';
+			' hs.httptestid='.zbx_dbstr($httptestid).' AND hs.httpstepid=hsi.httpstepid';
 		$items_db = DBselect($sql);
 		while($itemid = Dbfetch($items_db)){
 			$itemids[] = $itemid['itemid'];
@@ -486,17 +486,17 @@
 	}
 
 	function disable_httptest($httptestid){
-		$r = DBexecute('UPDATE httptest SET status='.HTTPTEST_STATUS_DISABLED.' WHERE httptestid='.$httptestid);
+		$r = DBexecute('UPDATE httptest SET status='.HTTPTEST_STATUS_DISABLED.' WHERE httptestid='.zbx_dbstr($httptestid));
 
 		$itemids = array();
-		$sql = 'SELECT hti.itemid FROM httptestitem hti WHERE hti.httptestid='.$httptestid;
+		$sql = 'SELECT hti.itemid FROM httptestitem hti WHERE hti.httptestid='.zbx_dbstr($httptestid);
 		$items_db = DBselect($sql);
 		while($itemid = Dbfetch($items_db)){
 			$itemids[] = $itemid['itemid'];
 		}
 
 		$sql = 'SELECT hsi.itemid FROM httpstep hs, httpstepitem hsi WHERE '.
-			' hs.httptestid='.$httptestid.' AND hs.httpstepid=hsi.httpstepid';
+			' hs.httptestid='.zbx_dbstr($httptestid).' AND hs.httpstepid=hsi.httpstepid';
 		$items_db = DBselect($sql);
 		while($itemid = Dbfetch($items_db)){
 			$itemids[] = $itemid['itemid'];
@@ -510,7 +510,7 @@
 	function delete_history_by_httptestid($httptestid){
 		$db_items = DBselect('SELECT DISTINCT i.itemid '.
 							' FROM items i, httpstepitem si, httpstep s '.
-							' WHERE s.httptestid='.$httptestid.
+							' WHERE s.httptestid='.zbx_dbstr($httptestid).
 								' AND si.httpstepid=s.httpstepid '.
 								' AND i.itemid=si.itemid');
 		while($item_data = DBfetch($db_items)){
@@ -520,11 +520,11 @@
 	}
 
 	function get_httptest_by_httptestid($httptestid){
-		return DBfetch(DBselect('select * from httptest where httptestid='.$httptestid));
+		return DBfetch(DBselect('select * from httptest where httptestid='.zbx_dbstr($httptestid)));
 	}
 
 	function get_httpstep_by_no($httptestid, $no){
-		return DBfetch(DBselect('select * from httpstep where httptestid='.$httptestid.' and no='.$no));
+		return DBfetch(DBselect('select * from httpstep where httptestid='.zbx_dbstr($httptestid).' and no='.zbx_dbstr($no)));
 	}
 
 	function get_httptests_by_hostid($hostids){
Index: frontends/php/include/acknow.inc.php
===================================================================
--- frontends/php/include/acknow.inc.php	(revision 38884)
+++ frontends/php/include/acknow.inc.php	(working copy)
@@ -23,7 +23,7 @@
 function get_last_event_by_triggerid($triggerid){
 	$event_data = DBfetch(DBselect('SELECT * '.
 				' FROM events '.
-				' WHERE objectid='.$triggerid.
+				' WHERE objectid='.zbx_dbstr($triggerid).
 					' and object='.EVENT_OBJECT_TRIGGER.
 				' ORDER BY objectid desc, object desc, eventid desc', 1));
 	if(!$event_data)
@@ -32,7 +32,7 @@
 }
 
 function get_acknowledges_by_eventid($eventid){
-	return DBselect("SELECT a.*, u.alias FROM acknowledges a LEFT JOIN users u ON u.userid=a.userid  WHERE a.eventid=$eventid");
+	return DBselect('SELECT a.*, u.alias FROM acknowledges a LEFT JOIN users u ON u.userid=a.userid  WHERE a.eventid='.zbx_dbstr($eventid));
 }
 
 function make_acktab_by_eventid($eventid){
Index: frontends/php/include/forms.inc.php
===================================================================
--- frontends/php/include/forms.inc.php	(revision 38884)
+++ frontends/php/include/forms.inc.php	(working copy)
@@ -37,12 +37,12 @@
 		$new_step	= get_request('new_step', null);
 
 		if((isset($_REQUEST['slideshowid']) && !isset($_REQUEST['form_refresh']))){
-			$slideshow_data = DBfetch(DBselect('SELECT * FROM slideshows WHERE slideshowid='.$_REQUEST['slideshowid']));
+			$slideshow_data = DBfetch(DBselect('SELECT * FROM slideshows WHERE slideshowid='.zbx_dbstr($_REQUEST['slideshowid'])));
 
 			$name		= $slideshow_data['name'];
 			$delay		= $slideshow_data['delay'];
 			$steps		= array();
-			$db_steps = DBselect('SELECT * FROM slides WHERE slideshowid='.$_REQUEST['slideshowid'].' order by step');
+			$db_steps = DBselect('SELECT * FROM slides WHERE slideshowid='.zbx_dbstr($_REQUEST['slideshowid']).' order by step');
 
 			while($step_data = DBfetch($db_steps)){
 				$steps[$step_data['step']] = array(
@@ -233,7 +233,7 @@
 			$user_groups = zbx_objectValues($user_groups, 'usrgrpid');
 			$user_groups = zbx_toHash($user_groups);
 
-			$db_medias = DBselect('SELECT m.* FROM media m WHERE m.userid='.$userid);
+			$db_medias = DBselect('SELECT m.* FROM media m WHERE m.userid='.zbx_dbstr($userid));
 			while($db_media = DBfetch($db_medias)){
 				$user_medias[] = array(
 					'mediaid' => $db_media['mediaid'],
@@ -642,7 +642,7 @@
 			$sql = 'SELECT DISTINCT u.userid '.
 						' FROM users u,users_groups ug '.
 						' WHERE u.userid=ug.userid '.
-							' AND ug.usrgrpid='.$_REQUEST['usrgrpid'];
+							' AND ug.usrgrpid='.zbx_dbstr($_REQUEST['usrgrpid']);
 
 			$db_users=DBselect($sql);
 
@@ -654,7 +654,7 @@
 					' FROM groups g '.
 						' LEFT JOIN rights r on r.id=g.groupid '.
 						' LEFT JOIN nodes n on n.nodeid='.DBid2nodeid('g.groupid').
-					' WHERE r.groupid='.$_REQUEST['usrgrpid'];
+					' WHERE r.groupid='.zbx_dbstr($_REQUEST['usrgrpid']);
 
 			$db_rights = DBselect($sql);
 			while($db_right = DBfetch($db_rights)){
@@ -716,7 +716,7 @@
 	$sql_where = '';
 	if($selusrgrp > 0) {
 		$sql_from = ', users_groups g ';
-		$sql_where = ' AND u.userid=g.userid AND g.usrgrpid='.$selusrgrp;
+		$sql_where = ' AND u.userid=g.userid AND g.usrgrpid='.zbx_dbstr($selusrgrp);
 	}
 	$sql = 'SELECT DISTINCT u.userid, u.alias '.
 			' FROM users u '.$sql_from.
@@ -1670,7 +1670,7 @@
 			do{
 				$sql = 'SELECT i.itemid, i.templateid, h.host'.
 						' FROM items i, hosts h'.
-						' WHERE i.itemid='.$itemid.
+						' WHERE i.itemid='.zbx_dbstr($itemid).
 							' AND h.hostid=i.hostid';
 				$itemFromDb = DBfetch(DBselect($sql));
 				if($itemFromDb){
@@ -2096,7 +2096,7 @@
 
 		$sql = 'SELECT DISTINCT applicationid,name '.
 				' FROM applications '.
-				' WHERE hostid='.$hostid.
+				' WHERE hostid='.zbx_dbstr($hostid).
 				' ORDER BY name';
 		$db_applications = DBselect($sql);
 		while($db_app = DBfetch($db_applications)){
@@ -2368,7 +2368,7 @@
 		if(isset($_REQUEST['hostid'])){
 			$sql = 'SELECT applicationid,name '.
 				' FROM applications '.
-				' WHERE hostid='.$_REQUEST['hostid'].
+				' WHERE hostid='.zbx_dbstr($_REQUEST['hostid']).
 				' ORDER BY name';
 			$db_applications = DBselect($sql);
 			while($db_app = DBfetch($db_applications)){
@@ -2578,7 +2578,7 @@
 			do{
 				$sql = 'SELECT t.triggerid, t.templateid, h.host'.
 						' FROM triggers t, functions f, items i, hosts h'.
-						' WHERE t.triggerid='.$trigid.
+						' WHERE t.triggerid='.zbx_dbstr($trigid).
 							' AND h.hostid=i.hostid'.
 							' AND i.itemid=f.itemid'.
 							' AND f.triggerid=t.triggerid';
@@ -2627,7 +2627,7 @@
 				$trigs=DBselect('SELECT t.triggerid,t.description,t.expression '.
 							' FROM triggers t,trigger_depends d '.
 							' WHERE t.triggerid=d.triggerid_up '.
-								' AND d.triggerid_down='.$_REQUEST['triggerid']);
+								' AND d.triggerid_down='.zbx_dbstr($_REQUEST['triggerid']));
 
 				while($trig=DBfetch($trigs)){
 					if(uint_in_array($trig['triggerid'],$dependencies))	continue;
@@ -3666,7 +3666,7 @@
 		if(isset($_REQUEST['screenid'])){
 			$result=DBselect('SELECT screenid,name,hsize,vsize '.
 						' FROM screens g '.
-						' WHERE screenid='.$_REQUEST['screenid']);
+						' WHERE screenid='.zbx_dbstr($_REQUEST['screenid']));
 			$row=DBfetch($result);
 			$frm_title = S_SCREEN.' "'.$row['name'].'"';
 		}
@@ -4202,7 +4202,7 @@
 			$host_groups = zbx_objectValues($host_groups, 'groupid');
 
 // read profile
-			$db_profiles = DBselect('SELECT * FROM hosts_profiles WHERE hostid='.$_REQUEST['hostid']);
+			$db_profiles = DBselect('SELECT * FROM hosts_profiles WHERE hostid='.zbx_dbstr($_REQUEST['hostid']));
 
 			$useprofile = 'no';
 			$db_profile = DBfetch($db_profiles);
@@ -4225,7 +4225,7 @@
 // BEGIN: HOSTS PROFILE EXTENDED Section
 			$useprofile_ext = 'no';
 
-			$db_profiles_alt = DBselect('SELECT * FROM hosts_profiles_ext WHERE hostid='.$_REQUEST['hostid']);
+			$db_profiles_alt = DBselect('SELECT * FROM hosts_profiles_ext WHERE hostid='.zbx_dbstr($_REQUEST['hostid']));
 			if($ext_host_profiles = DBfetch($db_profiles_alt)){
 				$useprofile_ext = 'yes';
 			}
@@ -4648,7 +4648,7 @@
 
 		$sql_fields = implode(', ', array_keys($table_titles)); //generate string of fields to get from DB
 
-		$sql = 'SELECT '.$sql_fields.' FROM hosts_profiles WHERE hostid='.$_REQUEST['hostid'];
+		$sql = 'SELECT '.$sql_fields.' FROM hosts_profiles WHERE hostid='.zbx_dbstr($_REQUEST['hostid']);
 		$result = DBselect($sql);
 
 		if($row = DBfetch($result)) {
@@ -4689,7 +4689,7 @@
 				'poc_2_screen' => S_POC_2_SCREEN, 'poc_2_notes' => S_POC_2_NOTES);
 
 		$sql_fields = implode(', ', array_keys($table_titles)); //generate string of fields to get from DB
-		$result = DBselect('SELECT '.$sql_fields.' FROM hosts_profiles_ext WHERE hostid='.$_REQUEST['hostid']);
+		$result = DBselect('SELECT '.$sql_fields.' FROM hosts_profiles_ext WHERE hostid='.zbx_dbstr($_REQUEST['hostid']));
 
 		if($row = DBfetch($result)) {
 			foreach($row as $key => $value) {
@@ -4852,7 +4852,7 @@
 			$sql = 'SELECT re.* '.
 				' FROM regexps re '.
 				' WHERE '.DBin_node('re.regexpid').
-					' AND re.regexpid='.$_REQUEST['regexpid'];
+					' AND re.regexpid='.zbx_dbstr($_REQUEST['regexpid']);
 			$regexp = DBfetch(DBSelect($sql));
 
 			$frm_title .= ' ['.$regexp['name'].']';
@@ -4864,7 +4864,7 @@
 			$sql = 'SELECT e.* '.
 					' FROM expressions e '.
 					' WHERE '.DBin_node('e.expressionid').
-						' AND e.regexpid='.$regexp['regexpid'].
+						' AND e.regexpid='.zbx_dbstr($regexp['regexpid']).
 					' ORDER BY e.expression_type';
 
 			$db_exps = DBselect($sql);
@@ -5006,7 +5006,7 @@
 			$sql = 'SELECT e.* '.
 					' FROM expressions e '.
 					' WHERE '.DBin_node('e.expressionid').
-						' AND e.regexpid='.$_REQUEST['regexpid'].
+						' AND e.regexpid='.zbx_dbstr($_REQUEST['regexpid']).
 					' ORDER BY e.expression_type';
 
 			$db_exps = DBselect($sql);
Index: frontends/php/include/triggers.inc.php
===================================================================
--- frontends/php/include/triggers.inc.php	(revision 38884)
+++ frontends/php/include/triggers.inc.php	(working copy)
@@ -132,7 +132,7 @@
 	function get_service_status_of_trigger($triggerid){
 		$sql = 'SELECT triggerid, priority '.
 				' FROM triggers '.
-				' WHERE triggerid='.$triggerid.
+				' WHERE triggerid='.zbx_dbstr($triggerid).
 					' AND status='.TRIGGER_STATUS_ENABLED.
 					' AND value='.TRIGGER_VALUE_TRUE;
 
@@ -322,7 +322,7 @@
 	}
 
 	function get_functions_by_triggerid($triggerid){
-		return DBselect('select * from functions where triggerid='.$triggerid);
+		return DBselect('select * from functions where triggerid='.zbx_dbstr($triggerid));
 	}
 
 /*
@@ -340,7 +340,7 @@
 	function get_triggers_by_hostid($hostid){
 		$db_triggers = DBselect('SELECT DISTINCT t.* '.
 								' FROM triggers t, functions f, items i '.
-								' WHERE i.hostid='.$hostid.
+								' WHERE i.hostid='.zbx_dbstr($hostid).
 									' AND f.itemid=i.itemid '.
 									' AND f.triggerid=t.triggerid');
 	return $db_triggers;
@@ -550,8 +550,8 @@
 
 		$result = DBexecute('INSERT INTO triggers '.
 			'  (triggerid,description,type,priority,status,comments,url,value,error,templateid) '.
-			" values ($triggerid,".zbx_dbstr($description).",$type,$priority,$status,".zbx_dbstr($comments).','.
-			zbx_dbstr($url).",2,'Trigger just added. No status update so far.',$templateid)");
+			' values ('.$triggerid.','.zbx_dbstr($description).','.zbx_dbstr($type).','.zbx_dbstr($priority).','.zbx_dbstr($status).','.zbx_dbstr($comments).','.
+			zbx_dbstr($url).',2,\'Trigger just added. No status update so far.\','.zbx_dbstr($templateid).')');
 
 		if (!$result) {
 			return	$result;
@@ -564,7 +564,7 @@
 			return false;
 		}
 
-		DBexecute('update triggers set expression='.zbx_dbstr($expression).' where triggerid='.$triggerid);
+		DBexecute('update triggers set expression='.zbx_dbstr($expression).' where triggerid='.zbx_dbstr($triggerid));
 
 		$trig_hosts = get_hosts_by_triggerid($triggerid);
 		$trig_host = DBfetch($trig_hosts);
@@ -618,13 +618,13 @@
 					// $hostid);
 		$sql='SELECT t2.triggerid, t2.expression '.
 				' FROM triggers t2, functions f1, functions f2, items i1, items i2 '.
-				' WHERE f1.triggerid='.$triggerid.
+				' WHERE f1.triggerid='.zbx_dbstr($triggerid).
 					' AND i1.itemid=f1.itemid '.
 					' AND f2.function=f1.function '.
 					' AND f2.parameter=f1.parameter '.
 					' AND i2.itemid=f2.itemid '.
 					' AND i2.key_=i1.key_ '.
-					' AND i2.hostid='.$hostid.
+					' AND i2.hostid='.zbx_dbstr($hostid).
 					' AND t2.triggerid=f2.triggerid '.
 					' AND t2.description='.zbx_dbstr($trigger['description']).
 					' AND t2.templateid=0 ';
@@ -650,9 +650,9 @@
 
 		$result = DBexecute('INSERT INTO triggers '.
 					' (triggerid,description,type,priority,status,comments,url,value,expression,templateid)'.
-					' VALUES ('.$newtriggerid.','.zbx_dbstr($trigger['description']).','.$trigger['type'].','.$trigger['priority'].','.
-					$trigger['status'].','.zbx_dbstr($trigger['comments']).','.
-					zbx_dbstr($trigger['url']).",2,'0',".($copy_mode ? 0 : $triggerid).')');
+					' VALUES ('.$newtriggerid.','.zbx_dbstr($trigger['description']).','.zbx_dbstr($trigger['type']).','.zbx_dbstr($trigger['priority']).','.
+					zbx_dbstr($trigger['status']).','.zbx_dbstr($trigger['comments']).','.
+					zbx_dbstr($trigger['url']).",2,'0',".($copy_mode ? 0 : zbx_dbstr($triggerid)).')');
 
 		if(!$result)
 			return $result;
@@ -665,7 +665,7 @@
 		while($function = DBfetch($functions)){
 			$item = get_item_by_itemid($function['itemid']);
 
-			$host_items = DBselect('SELECT * FROM items WHERE key_='.zbx_dbstr($item['key_']).' AND hostid='.$host['hostid']);
+			$host_items = DBselect('SELECT * FROM items WHERE key_='.zbx_dbstr($item['key_']).' AND hostid='.zbx_dbstr($host['hostid']));
 			$host_item = DBfetch($host_items);
 			if(!$host_item){
 				error(S_MISSING_KEY.SPACE.'"'.$item['key_'].'"'.SPACE.S_FOR_HOST_SMALL.SPACE.'"'.$host['host'].'"');
@@ -675,7 +675,7 @@
 			$newfunctionid=get_dbid('functions','functionid');
 
 			$result = DBexecute('INSERT INTO functions (functionid,itemid,triggerid,function,parameter) '.
-				" values ($newfunctionid,".$host_item['itemid'].','.$newtriggerid.','.
+				' values ('.zbx_dbstr($newfunctionid).','.zbx_dbstr($host_item['itemid']).','.zbx_dbstr($newtriggerid).','.
 				zbx_dbstr($function['function']).','.zbx_dbstr($function['parameter']).')');
 
 			$newexpression = str_replace(
@@ -684,7 +684,7 @@
 				$newexpression);
 		}
 
-		DBexecute('UPDATE triggers SET expression='.zbx_dbstr($newexpression).' WHERE triggerid='.$newtriggerid);
+		DBexecute('UPDATE triggers SET expression='.zbx_dbstr($newexpression).' WHERE triggerid='.zbx_dbstr($newtriggerid));
 
 		info(S_ADDED_TRIGGER.SPACE.'"'.$host['host'].':'.$trigger['description'].'"');
 		add_audit_ext(AUDIT_ACTION_ADD, AUDIT_RESOURCE_TRIGGER, $newtriggerid, $host['host'].':'.$trigger['description'], NULL, NULL, NULL);
@@ -870,7 +870,7 @@
 				$state='';
 				$sql = 'SELECT h.host,i.itemid,i.key_,f.function,f.triggerid,f.parameter,i.itemid,i.status, i.type'.
 						' FROM items i,functions f,hosts h'.
-						' WHERE f.functionid='.$functionid.
+						' WHERE f.functionid='.zbx_dbstr($functionid).
 							' AND i.itemid=f.itemid '.
 							' AND h.hostid=i.hostid';
 
@@ -1243,7 +1243,7 @@
 							' FROM functions f,items i,hosts h'.
 							' WHERE f.itemid=i.itemid'.
 								' AND i.hostid=h.hostid'.
-								' AND f.functionid='.$functionid;
+								' AND f.functionid='.zbx_dbstr($functionid);
 					$host = DBfetch(DBselect($sql));
 					if (is_null($host['host'])) {
 						$host['host'] = $macro;
@@ -1261,7 +1261,7 @@
 					$sql = 'SELECT i.lastvalue,i.value_type,i.itemid,i.valuemapid,i.units'.
 							' FROM items i,functions f'.
 							' WHERE i.itemid=f.itemid'.
-							' AND f.functionid='.$functionid;
+							' AND f.functionid='.zbx_dbstr($functionid);
 					$itemData = DBfetch(DBselect($sql));
 					$description = str_replace($macro, format_lastvalue($itemData), $description);
 				}
@@ -1276,7 +1276,7 @@
 						$sql = 'SELECT i.value_type,i.itemid,i.valuemapid,i.units'.
 								' FROM items i,functions f'.
 								' WHERE i.itemid=f.itemid'.
-								' AND f.functionid='.$functionid;
+								' AND f.functionid='.zbx_dbstr($functionid);
 						$itemData = DBfetch(DBselect($sql));
 					}
 
@@ -1309,7 +1309,7 @@
 				' WHERE f.triggerid=t.triggerid '.
 					' AND i.itemid=f.itemid '.
 					' AND h.hostid=i.hostid '.
-					' AND t.triggerid='.$triggerid;
+					' AND t.triggerid='.zbx_dbstr($triggerid);
 		$trigger = DBfetch(DBselect($sql));
 
 	return expand_trigger_description_by_data($trigger);
@@ -1341,7 +1341,7 @@
 		}
 
 		if(!empty($triggers)){
-			DBexecute('UPDATE triggers SET value='.TRIGGER_VALUE_UNKNOWN.', lastchange='.$now.' WHERE '.DBcondition('triggerid',$triggers));
+			DBexecute('UPDATE triggers SET value='.TRIGGER_VALUE_UNKNOWN.', lastchange='.zbx_dbstr($now).' WHERE '.DBcondition('triggerid',$triggers));
 		}
 	return true;
 	}
@@ -1660,7 +1660,7 @@
 	function get_trigger_dependencies_by_triggerid($triggerid){
 		$result = array();
 
-		$db_deps = DBselect('SELECT * FROM trigger_depends WHERE triggerid_down='.$triggerid);
+		$db_deps = DBselect('SELECT * FROM trigger_depends WHERE triggerid_down='.zbx_dbstr($triggerid));
 		while($db_dep = DBfetch($db_deps))
 			$result[] = $db_dep['triggerid_up'];
 
@@ -1742,7 +1742,7 @@
 	function insert_dependency($triggerid_down, $triggerid_up) {
 		$triggerdepid = get_dbid('trigger_depends', 'triggerdepid');
 		return DBexecute('INSERT INTO trigger_depends (triggerdepid,triggerid_down,triggerid_up)'.
-				' VALUES ('.$triggerdepid.','.$triggerid_down.','.$triggerid_up.')');
+				' VALUES ('.$triggerdepid.','.zbx_dbstr($triggerid_down).','.zbx_dbstr($triggerid_up).')');
 	}
 
 	function replace_triggers_depenedencies($new_triggerids){
@@ -1771,10 +1771,10 @@
 		foreach($deps as $id => $val){
 			$sql = 'SELECT t.triggerid '.
 				' FROM triggers t,functions f,items i '.
-				' WHERE t.templateid='.$val.
+				' WHERE t.templateid='.zbx_dbstr($val).
 					' AND f.triggerid=t.triggerid '.
 					' AND f.itemid=i.itemid '.
-					' AND i.hostid='.$hostid;
+					' AND i.hostid='.zbx_dbstr($hostid);
 			if($db_new_dep = DBfetch(DBselect($sql))){
 				$deps[$id] = $db_new_dep['triggerid'];
 			}
@@ -1810,7 +1810,7 @@
 		$level++;
 		$result = true;
 
-		$sql = 'SELECT triggerid_up FROM trigger_depends WHERE triggerid_down='.$triggerid_up;
+		$sql = 'SELECT triggerid_up FROM trigger_depends WHERE triggerid_down='.zbx_dbstr($triggerid_up);
 		$res = DBselect($sql);
 		while(($trig = DBfetch($res)) && $result){
 			$result &= check_dependency_by_triggerid($triggerid,$trig['triggerid_up'],$level);		// RECURSION!!!
@@ -2041,7 +2041,7 @@
 			}
 
 			if ($unlink_mode) {
-				if (DBexecute('UPDATE triggers SET templateid=0 WHERE triggerid='.$trigger['triggerid'])) {
+				if (DBexecute('UPDATE triggers SET templateid=0 WHERE triggerid='.zbx_dbstr($trigger['triggerid']))) {
 					info(sprintf(S_TRIGGER_UNLINKED, $host['host'].':'.$trigger['description']));
 				}
 			}
@@ -2296,7 +2296,7 @@
 			$dep_table->setAttribute('style', 'width: 200px;');
 			$dep_table->addRow(bold(S_DEPENDS_ON.':'));
 
-			$sql_dep = 'SELECT * FROM trigger_depends WHERE triggerid_down='.$triggerid;
+			$sql_dep = 'SELECT * FROM trigger_depends WHERE triggerid_down='.zbx_dbstr($triggerid);
 			$dep_res = DBselect($sql_dep);
 			while($dep_row = DBfetch($dep_res)){
 				$dep_table->addRow(SPACE.'-'.SPACE.expand_trigger_description($dep_row['triggerid_up']));
@@ -2318,7 +2318,7 @@
 			$dep_table->setAttribute('style', 'width: 200px;');
 			$dep_table->addRow(bold(S_DEPENDENT.':'));
 
-			$sql_dep = 'SELECT * FROM trigger_depends WHERE triggerid_up='.$triggerid;
+			$sql_dep = 'SELECT * FROM trigger_depends WHERE triggerid_up='.zbx_dbstr($triggerid);
 			$dep_res = DBselect($sql_dep);
 			while($dep_row = DBfetch($dep_res)){
 				$dep_table->addRow(SPACE.'-'.SPACE.expand_trigger_description($dep_row['triggerid_down']));
@@ -2363,9 +2363,9 @@
 		if(($period_start>0) && ($period_start <= time())){
 			$sql='SELECT e.eventid, e.value '.
 					' FROM events e '.
-					' WHERE e.objectid='.$triggerid.
+					' WHERE e.objectid='.zbx_dbstr($triggerid).
 						' AND e.object='.EVENT_OBJECT_TRIGGER.
-						' AND e.clock<'.$period_start.
+						' AND e.clock<'.zbx_dbstr($period_start).
 					' ORDER BY e.eventid DESC';
 			if($row = DBfetch(DBselect($sql,1))){
 				$start_value = $row['value'];
@@ -2375,11 +2375,11 @@
 
 		$sql='SELECT COUNT(*) as cnt, MIN(clock) as minn, MAX(clock) as maxx '.
 				' FROM events '.
-				' WHERE objectid='.$triggerid.
+				' WHERE objectid='.zbx_dbstr($triggerid).
 					' AND object='.EVENT_OBJECT_TRIGGER;
 
-		if($period_start!=0)	$sql .= ' AND clock>='.$period_start;
-		if($period_end!=0)		$sql .= ' AND clock<='.$period_end;
+		if($period_start!=0)	$sql .= ' AND clock>='.zbx_dbstr($period_start);
+		if($period_end!=0)		$sql .= ' AND clock<='.zbx_dbstr($period_end);
 //SDI($sql);
 
 		$row=DBfetch(DBselect($sql));
@@ -2419,10 +2419,10 @@
 		$rows=0;
 		$sql = 'SELECT eventid,clock,value '.
 				' FROM events '.
-				' WHERE objectid='.$triggerid.
+				' WHERE objectid='.zbx_dbstr($triggerid).
 					' AND object='.EVENT_OBJECT_TRIGGER.
-					' AND clock>='.$min.
-					' AND clock<='.$max.
+					' AND clock>='.zbx_dbstr($min).
+					' AND clock<='.zbx_dbstr($max).
 				' ORDER BY clock ASC, eventid ASC';
 		$result=DBselect($sql);
 		while($row=DBfetch($result)){
@@ -2506,7 +2506,7 @@
 
 		$sql = 'SELECT t.triggerid, t.value '.
 				' FROM trigger_depends d, triggers t '.
-				' WHERE d.triggerid_down='.$triggerid.
+				' WHERE d.triggerid_down='.zbx_dbstr($triggerid).
 					' AND d.triggerid_up=t.triggerid';
 
 		$result = DBselect($sql);
@@ -2589,7 +2589,7 @@
 		$functionid=trigger_get_N_functionid($expression,$function);
 		if(isset($functionid)){
 			$row=DBfetch(DBselect('select i.* from items i, functions f '.
-				' where i.itemid=f.itemid and f.functionid='.$functionid));
+				' where i.itemid=f.itemid and f.functionid='.zbx_dbstr($functionid)));
 			if($row)
 			{
 				$result=($flag == ZBX_FLAG_TRIGGER)?
Index: frontends/php/include/regexp.inc.php
===================================================================
--- frontends/php/include/regexp.inc.php	(revision 38884)
+++ frontends/php/include/regexp.inc.php	(working copy)
@@ -23,7 +23,7 @@
 	$sql = 'SELECT re.* '.
 					' FROM regexps re '.
 					' WHERE '.DBin_node('re.regexpid').
-						' AND regexpid='.$regexpid;
+						' AND regexpid='.zbx_dbstr($regexpid);
 
 	$db_regexp = DBfetch(DBselect($sql));
 return $db_regexp;
@@ -80,7 +80,7 @@
 	$sql = 'UPDATE regexps SET '.
 				' name='.zbx_dbstr($regexp['name']).','.
 				' test_string='.zbx_dbstr($regexp['test_string']).
-			' WHERE regexpid='.$regexpid;
+			' WHERE regexpid='.zbx_dbstr($regexpid);
 	$result = DBexecute($sql);
 return $result;
 }
@@ -117,8 +117,8 @@
 				' VALUES ('.$expressionid.','.
 						$regexpid.','.
 						zbx_dbstr($expression['expression']).','.
-						$expression['expression_type'].','.
-						$expression['case_sensitive'].','.
+						zbx_dbstr($expression['expression_type']).','.
+						zbx_dbstr($expression['case_sensitive']).','.
 						zbx_dbstr($expression['exp_delimiter']).')');
 
 return $result?$expressionid:false;
Index: frontends/php/include/actions.inc.php
===================================================================
--- frontends/php/include/actions.inc.php	(revision 38884)
+++ frontends/php/include/actions.inc.php	(working copy)
@@ -95,7 +95,7 @@
 }
 
 function get_action_by_actionid($actionid){
-	$sql='select * from actions where actionid='.$actionid;
+	$sql='select * from actions where actionid='.zbx_dbstr($actionid);
 	$result=DBselect($sql);
 
 	if($row=DBfetch($result)){
@@ -220,7 +220,7 @@
 			break;
 		case CONDITION_TYPE_DCHECK:
 			$row = DBfetch(DBselect('SELECT DISTINCT r.name,c.dcheckid,c.type,c.key_,c.snmp_community,c.ports'.
-					' FROM drules r,dchecks c WHERE r.druleid=c.druleid AND c.dcheckid='.$value));
+					' FROM drules r,dchecks c WHERE r.druleid=c.druleid AND c.dcheckid='.zbx_dbstr($value)));
 			$str_val = $row['name'].':'.discovery_check2str($row['type'],
 					$row['snmp_community'], $row['key_'], $row['ports']);
 			break;
@@ -342,7 +342,7 @@
 							$sql = 'SELECT a.def_shortdata,a.def_longdata '.
 									' FROM actions a, operations o '.
 									' WHERE a.actionid=o.actionid '.
-										' AND o.operationid='.$data['operationid'];
+										' AND o.operationid='.zbx_dbstr($data['operationid']);
 							if($rows = DBfetch(DBselect($sql,1))){
 								$temp = bold(S_SUBJECT.': ');
 								$result = $temp->ToString()."\n".$rows['def_shortdata']."\n";
@@ -583,7 +583,7 @@
 
 function	update_action_status($actionid, $status)
 {
-	return DBexecute("update actions set status=$status where actionid=$actionid");
+	return DBexecute('update actions set status='.zbx_dbstr($status).' where actionid='.zbx_dbstr($actionid));
 }
 
 function validate_condition($conditiontype, $value){
@@ -1037,7 +1037,7 @@
 	$hostids = array();
 	$sql = 'SELECT DISTINCT i.hostid '.
 			' FROM events e, functions f, items i '.
-			' WHERE e.eventid='.$eventid.
+			' WHERE e.eventid='.zbx_dbstr($eventid).
 				' AND e.object='.EVENT_SOURCE_TRIGGERS.
 				' AND f.triggerid=e.objectid '.
 				' AND i.itemid=f.itemid';
@@ -1071,8 +1071,8 @@
 			' FROM events e,alerts a '.
 				' LEFT JOIN users u ON u.userid=a.userid '.
 				' LEFT JOIN media_type mt ON mt.mediatypeid=a.mediatypeid'.
-			' WHERE a.eventid='.$eventid.
-				(is_null($status)?'':' AND a.status='.$status).
+			' WHERE a.eventid='.zbx_dbstr($eventid).
+				(is_null($status)?'':' AND a.status='.zbx_dbstr($status)).
 				' AND e.eventid = a.eventid'.
 				' AND a.alerttype IN ('.ALERT_TYPE_MESSAGE.','.ALERT_TYPE_COMMAND.')'.
 				' AND '.DBcondition('e.objectid',$available_triggers).
@@ -1127,7 +1127,7 @@
 
 	$sql='SELECT COUNT(a.alertid) as cnt_all'.
 			' FROM alerts a '.
-			' WHERE a.eventid='.$eventid.
+			' WHERE a.eventid='.zbx_dbstr($eventid).
 				' AND a.alerttype in ('.ALERT_TYPE_MESSAGE.','.ALERT_TYPE_COMMAND.')';
 
 	$alerts=DBfetch(DBselect($sql));
@@ -1137,7 +1137,7 @@
 // Sent
 		$sql='SELECT COUNT(a.alertid) as sent '.
 				' FROM alerts a '.
-				' WHERE a.eventid='.$eventid.
+				' WHERE a.eventid='.zbx_dbstr($eventid).
 					' AND a.alerttype in ('.ALERT_TYPE_MESSAGE.','.ALERT_TYPE_COMMAND.')'.
 					' AND a.status='.ALERT_STATUS_SENT;
 
@@ -1147,7 +1147,7 @@
 // In progress
 		$sql='SELECT COUNT(a.alertid) as inprogress '.
 				' FROM alerts a '.
-				' WHERE a.eventid='.$eventid.
+				' WHERE a.eventid='.zbx_dbstr($eventid).
 					' AND a.alerttype in ('.ALERT_TYPE_MESSAGE.','.ALERT_TYPE_COMMAND.')'.
 					' AND a.status='.ALERT_STATUS_NOT_SENT;
 
@@ -1156,7 +1156,7 @@
 // Failed
 		$sql='SELECT COUNT(a.alertid) as failed '.
 				' FROM alerts a '.
-				' WHERE a.eventid='.$eventid.
+				' WHERE a.eventid='.zbx_dbstr($eventid).
 					' AND a.alerttype in ('.ALERT_TYPE_MESSAGE.','.ALERT_TYPE_COMMAND.')'.
 					' AND a.status='.ALERT_STATUS_FAILED;
 
@@ -1194,7 +1194,7 @@
 
 	$sql='SELECT COUNT(a.alertid) as cnt '.
 			' FROM alerts a '.
-			' WHERE a.eventid='.$eventid.
+			' WHERE a.eventid='.zbx_dbstr($eventid).
 				' AND a.alerttype in ('.ALERT_TYPE_MESSAGE.','.ALERT_TYPE_COMMAND.')';
 
 
@@ -1203,7 +1203,7 @@
 	if(isset($alerts['cnt']) && ($alerts['cnt'] > 0)){
 		$sql='SELECT COUNT(a.alertid) as sent '.
 				' FROM alerts a '.
-				' WHERE a.eventid='.$eventid.
+				' WHERE a.eventid='.zbx_dbstr($eventid).
 					' AND a.alerttype in ('.ALERT_TYPE_MESSAGE.','.ALERT_TYPE_COMMAND.')'.
 					' AND a.status='.ALERT_STATUS_SENT;
 
@@ -1219,7 +1219,7 @@
 
 		$sql='SELECT COUNT(a.alertid) as inprogress '.
 				' FROM alerts a '.
-				' WHERE a.eventid='.$eventid.
+				' WHERE a.eventid='.zbx_dbstr($eventid).
 					' AND a.alerttype in ('.ALERT_TYPE_MESSAGE.','.ALERT_TYPE_COMMAND.')'.
 					' AND a.status='.ALERT_STATUS_NOT_SENT;
 
@@ -1235,7 +1235,7 @@
 
 		$sql='SELECT COUNT(a.alertid) as failed '.
 				' FROM alerts a '.
-				' WHERE a.eventid='.$eventid.
+				' WHERE a.eventid='.zbx_dbstr($eventid).
 					' AND a.alerttype in ('.ALERT_TYPE_MESSAGE.','.ALERT_TYPE_COMMAND.')'.
 					' AND a.status='.ALERT_STATUS_FAILED;
 
Index: frontends/php/include/screens.inc.php
===================================================================
--- frontends/php/include/screens.inc.php	(revision 38884)
+++ frontends/php/include/screens.inc.php	(working copy)
@@ -26,7 +26,7 @@
 <?php
 
 	function get_screen_by_screenid($screenid){
-		$result = DBselect("select * from screens where screenid=$screenid");
+		$result = DBselect('select * from screens where screenid='.zbx_dbstr($screenid));
 		$row=DBfetch($result);
 		if($row){
 			return	$row;
@@ -38,8 +38,7 @@
 	function check_screen_recursion($mother_screenid, $child_screenid){
 		if((bccomp($mother_screenid , $child_screenid)==0))	return TRUE;
 
-		$db_scr_items = DBselect("select resourceid from screens_items where".
-			" screenid=$child_screenid and resourcetype=".SCREEN_RESOURCE_SCREEN);
+		$db_scr_items = DBselect('select resourceid from screens_items where screenid='.zbx_dbstr($child_screenid).' and resourcetype='.SCREEN_RESOURCE_SCREEN);
 		while($scr_item = DBfetch($db_scr_items)){
 			if(check_screen_recursion($mother_screenid,$scr_item["resourceid"]))
 				return TRUE;
@@ -50,7 +49,7 @@
 	function get_slideshow($slideshowid, $step, $effectiveperiod=NULL){
 		$sql = 'SELECT min(step) as min_step, max(step) as max_step '.
 				' FROM slides '.
-				' WHERE slideshowid='.$slideshowid;
+				' WHERE slideshowid='.zbx_dbstr($slideshowid);
 		$slide_data = DBfetch(DBselect($sql));
 		if(!$slide_data || is_null($slide_data['min_step'])){
 			return false;
@@ -66,9 +65,9 @@
 
 		$sql = 'SELECT sl.* '.
 				' FROM slides sl, slideshows ss '.
-				' WHERE ss.slideshowid='.$slideshowid.
+				' WHERE ss.slideshowid='.zbx_dbstr($slideshowid).
 					' and sl.slideshowid=ss.slideshowid '.
-					' and sl.step='.$curr_step;
+					' and sl.step='.zbx_dbstr($curr_step);
 		$slide_data = DBfetch(DBselect($sql));
 
 	return $slide_data;
@@ -80,7 +79,7 @@
 
 		$sql = 'SELECT slideshowid '.
 				' FROM slideshows '.
-				' WHERE slideshowid='.$slideshowid.
+				' WHERE slideshowid='.zbx_dbstr($slideshowid).
 					' AND '.DBin_node('slideshowid', get_current_nodeid(null,$perm));
 		if(DBselect($sql)){
 			$result = true;
@@ -88,7 +87,7 @@
 			$screenids = array();
 			$sql = 'SELECT DISTINCT screenid '.
 					' FROM slides '.
-					' WHERE slideshowid='.$slideshowid;
+					' WHERE slideshowid='.zbx_dbstr($slideshowid);
 			$db_screens = DBselect($sql);
 			while($slide_data = DBfetch($db_screens)){
 				$screenids[$slide_data['screenid']] = $slide_data['screenid'];
@@ -111,7 +110,7 @@
 	}
 
 	function get_slideshow_by_slideshowid($slideshowid){
-		return DBfetch(DBselect('select * from slideshows where slideshowid='.$slideshowid));
+		return DBfetch(DBselect('select * from slideshows where slideshowid='.zbx_dbstr($slideshowid)));
 	}
 
 	function add_slideshow($name, $delay, $slides){
@@ -144,7 +143,7 @@
 
 // TODO: resulve conflict about regression of delay per slide
 			$result = DBexecute('INSERT INTO slides (slideid,slideshowid,screenid,step,delay) '.
-								' VALUES ('.$slideid.','.$slideshowid.','.$slide['screenid'].','.($i++).','.$slide['delay'].')');
+								' VALUES ('.$slideid.','.zbx_dbstr($slideshowid).','.zbx_dbstr($slide['screenid']).','.($i++).','.zbx_dbstr($slide['delay']).')');
 			if(!$result) return false;
 		}
 
@@ -171,17 +170,17 @@
 			if(!isset($slide['delay'])) $slide['delay'] = 0;
 		}
 
-		if(!$result = DBexecute('UPDATE slideshows SET name='.zbx_dbstr($name).',delay='.$delay.' WHERE slideshowid='.$slideshowid))
+		if(!$result = DBexecute('UPDATE slideshows SET name='.zbx_dbstr($name).',delay='.zbx_dbstr($delay).' WHERE slideshowid='.zbx_dbstr($slideshowid)))
 			return false;
 
-		DBexecute('DELETE FROM slides where slideshowid='.$slideshowid);
+		DBexecute('DELETE FROM slides where slideshowid='.zbx_dbstr($slideshowid));
 
 		$i = 0;
 		foreach($slides as $slide){
 			$slideid = get_dbid('slides','slideid');
 			if(!isset($slide['delay'])) $slide['delay'] = $delay;
 			$result = DBexecute('INSERT INTO slides (slideid,slideshowid,screenid,step,delay) '.
-				' VALUES ('.$slideid.','.$slideshowid.','.$slide['screenid'].','.($i++).','.$slide['delay'].')');
+				' VALUES ('.$slideid.','.zbx_dbstr($slideshowid).','.zbx_dbstr($slide['screenid']).','.($i++).','.zbx_dbstr($slide['delay']).')');
 			if(!$result){
 				return false;
 			}
@@ -192,9 +191,9 @@
 
 	function delete_slideshow($slideshowid){
 
-		$result = DBexecute('DELETE FROM slideshows where slideshowid='.$slideshowid);
-		$result &= DBexecute('DELETE FROM slides where slideshowid='.$slideshowid);
-		$result &= DBexecute("DELETE FROM profiles WHERE idx='web.favorite.screenids' AND source='slideshowid' AND value_id=$slideshowid");
+		$result = DBexecute('DELETE FROM slideshows where slideshowid='.zbx_dbstr($slideshowid));
+		$result &= DBexecute('DELETE FROM slides where slideshowid='.zbx_dbstr($slideshowid));
+		$result &= DBexecute('DELETE FROM profiles WHERE idx=\'web.favorite.screenids\' AND source=\'slideshowid\' AND value_id='.zbx_dbstr($slideshowid));
 
 		return $result;
 	}
@@ -282,13 +281,13 @@
 		if($config == 0){
 			$sql = 'SELECT screenitemid '.
 			' FROM screens_items '.
-			' WHERE screenid='.$elid.
+			' WHERE screenid='.zbx_dbstr($elid).
 				' AND dynamic='.SCREEN_DYNAMIC_ITEM;
 		}
 		else{
 			$sql = 'SELECT si.screenitemid '.
 			' FROM slides s, screens_items si '.
-			' WHERE s.slideshowid='.$elid.
+			' WHERE s.slideshowid='.zbx_dbstr($elid).
 				' AND si.screenid=s.screenid'.
 				' AND si.dynamic='.SCREEN_DYNAMIC_ITEM;
 		}
@@ -306,8 +305,8 @@
 		if(isset($_REQUEST['screenitemid'])){
 			$sql = 'SELECT * '.
 					' FROM screens_items'.
-					' WHERE screenid='.$_REQUEST['screenid'].
-						' AND screenitemid='.$_REQUEST['screenitemid'];
+					' WHERE screenid='.zbx_dbstr($_REQUEST['screenid']).
+						' AND screenitemid='.zbx_dbstr($_REQUEST['screenitemid']);
 			$iresult=DBSelect($sql);
 
 			$form->addVar('screenitemid',$_REQUEST['screenitemid']);
@@ -600,7 +599,7 @@
 				$result=DBselect('SELECT DISTINCT n.name as node_name,s.screenid,s.name '.
 							' FROM screens s '.
 								' LEFT JOIN nodes n ON n.nodeid='.DBid2nodeid('s.screenid').
-							' WHERE s.screenid='.$resourceid);
+							' WHERE s.screenid='.zbx_dbstr($resourceid));
 
 				while($row=DBfetch($result)){
 					$r = CScreen::get(array(
@@ -635,7 +634,7 @@
 						' FROM hosts_groups hg, groups g '.
 							' LEFT JOIN nodes n ON n.nodeid='.DBid2nodeid('g.groupid').
 						' WHERE '.DBcondition('g.groupid',$available_groups).
-							' AND g.groupid='.$resourceid);
+							' AND g.groupid='.zbx_dbstr($resourceid));
 
 				while($row=DBfetch($result)){
 					$row['node_name'] = isset($row['node_name']) ? '('.$row['node_name'].') ' : '';
@@ -770,11 +769,11 @@
 		if(is_null($effectiveperiod))
 			$effectiveperiod = ZBX_MIN_PERIOD;
 
-		$result=DBselect('SELECT name,hsize,vsize FROM screens WHERE screenid='.$screenid);
+		$result=DBselect('SELECT name,hsize,vsize FROM screens WHERE screenid='.zbx_dbstr($screenid));
 		$row=DBfetch($result);
 		if(!$row) return new CTableInfo(S_NO_SCREENS_DEFINED);
 
-		$sql = 'SELECT * FROM screens_items WHERE screenid='.$screenid;
+		$sql = 'SELECT * FROM screens_items WHERE screenid='.zbx_dbstr($screenid);
 		$iresult = DBSelect($sql);
 
 		$skip_field = array();
Index: frontends/php/include/perm.inc.php
===================================================================
--- frontends/php/include/perm.inc.php	(revision 38884)
+++ frontends/php/include/perm.inc.php	(working copy)
@@ -24,7 +24,7 @@
 	$sessionid = md5(time().$password.$name.rand(0,10000000));
 	zbx_setcookie('zbx_sessionid',$sessionid);
 
-	DBexecute('INSERT INTO sessions (sessionid,userid,lastaccess,status) VALUES ('.zbx_dbstr($sessionid).','.$userid.','.time().','.ZBX_SESSION_ACTIVE.')');
+	DBexecute('INSERT INTO sessions (sessionid,userid,lastaccess,status) VALUES ('.zbx_dbstr($sessionid).','.zbx_dbstr($userid).','.time().','.ZBX_SESSION_ACTIVE.')');
 
 return $sessionid;
 }
@@ -84,7 +84,7 @@
 function  check_perm2system($userid){
 	$sql = 'SELECT g.usrgrpid '.
 		' FROM usrgrp g, users_groups ug '.
-		' WHERE ug.userid = '.$userid.
+		' WHERE ug.userid = '.zbx_dbstr($userid).
 			' AND g.usrgrpid = ug.usrgrpid '.
 			' AND g.users_status = '.GROUP_STATUS_DISABLED;
 	if($res = DBfetch(DBselect($sql,1))){
@@ -128,7 +128,7 @@
 
 	$sql = 'SELECT MAX(g.gui_access) as gui_access '.
 		' FROM usrgrp g, users_groups ug '.
-		' WHERE ug.userid='.$userid.
+		' WHERE ug.userid='.zbx_dbstr($userid).
 			' AND g.usrgrpid=ug.usrgrpid ';
 	$acc = DBfetch(DBselect($sql));
 
@@ -142,7 +142,7 @@
 function get_user_debug_mode($userid){
 	$sql = 'SELECT g.usrgrpid '.
 			' FROM usrgrp g, users_groups ug '.
-			' WHERE ug.userid = '.$userid.
+			' WHERE ug.userid = '.zbx_dbstr($userid).
 				' AND g.usrgrpid = ug.usrgrpid '.
 				' AND g.debug_mode = '.GROUP_DEBUG_MODE_ENABLED;
 	if($res = DBfetch(DBselect($sql,1))){
@@ -261,7 +261,7 @@
 			' LEFT JOIN hosts_groups hg ON hg.hostid=h.hostid '.
 			' LEFT JOIN groups g ON g.groupid=hg.groupid '.
 			' LEFT JOIN rights r ON r.id=g.groupid '.
-			' LEFT JOIN users_groups ug ON ug.usrgrpid=r.groupid and ug.userid='.$userid.
+			' LEFT JOIN users_groups ug ON ug.usrgrpid=r.groupid and ug.userid='.zbx_dbstr($userid).
 			' LEFT JOIN nodes n ON '.DBid2nodeid('h.hostid').'=n.nodeid '.
 		$where.
 		' GROUP BY h.hostid,n.nodeid,n.name,h.host,ug.userid '.
@@ -444,7 +444,7 @@
 	foreach($node_data as $nodeid => $node){
 		switch($perm_res){
 			case PERM_RES_DATA_ARRAY:
-				$db_node = DBfetch(DBselect('SELECT * FROM nodes WHERE nodeid='.$nodeid.' ORDER BY name'));
+				$db_node = DBfetch(DBselect('SELECT * FROM nodes WHERE nodeid='.zbx_dbstr($nodeid).' ORDER BY name'));
 
 				if(!ZBX_DISTRIBUTED){
 					if(!$node){
@@ -671,7 +671,7 @@
 	foreach($node_data as $nodeid => $node){
 		switch($perm_res){
 			case PERM_RES_DATA_ARRAY:
-				$db_node = DBfetch(DBselect('SELECT * FROM nodes WHERE nodeid='.$nodeid));
+				$db_node = DBfetch(DBselect('SELECT * FROM nodes WHERE nodeid='.zbx_dbstr($nodeid)));
 
 				if(!ZBX_DISTRIBUTED){
 					if(!$node){
Index: frontends/php/include/blocks.inc.php
===================================================================
--- frontends/php/include/blocks.inc.php	(revision 38884)
+++ frontends/php/include/blocks.inc.php	(working copy)
@@ -982,7 +982,7 @@
 		$event_sql = 'SELECT e.eventid, e.value, e.clock, e.objectid as triggerid, e.acknowledged'.
 					' FROM events e'.
 					' WHERE e.object='.EVENT_OBJECT_TRIGGER.
-						' AND e.objectid='.$trigger['triggerid'].
+						' AND e.objectid='.zbx_dbstr($trigger['triggerid']).
 						' AND e.value='.TRIGGER_VALUE_TRUE.
 					' ORDER by e.object DESC, e.objectid DESC, e.eventid DESC';
 		$res_events = DBSelect($event_sql,1);
@@ -1073,7 +1073,7 @@
 
 		$sql = 'SELECT DISTINCT ht.name, ht.httptestid, ht.curstate, ht.lastfailedstep '.
 				' FROM httptest ht, applications a, hosts_groups hg, groups g '.
-				' WHERE g.groupid='.$group['groupid'].
+				' WHERE g.groupid='.zbx_dbstr($group['groupid']).
 					' AND '.DBcondition('hg.hostid',$available_hosts).
 					' AND hg.groupid=g.groupid '.
 					' AND a.hostid=hg.hostid '.
Index: frontends/php/include/export.inc.php
===================================================================
--- frontends/php/include/export.inc.php	(revision 38884)
+++ frontends/php/include/export.inc.php	(working copy)
@@ -756,7 +756,7 @@
 
 // Deleteing all selements (with links)
 					$db_selementids = array();
-					$res = DBselect('SELECT selementid FROM sysmaps_elements WHERE sysmapid='.$sysmap['sysmapid']);
+					$res = DBselect('SELECT selementid FROM sysmaps_elements WHERE sysmapid='.zbx_dbstr($sysmap['sysmapid']));
 					while($db_selement = DBfetch($res)){
 						$db_selementids[$db_selement['selementid']] = $db_selement['selementid'];
 					}
Index: frontends/php/include/items.inc.php
===================================================================
--- frontends/php/include/items.inc.php	(revision 38884)
+++ frontends/php/include/items.inc.php	(working copy)
@@ -192,7 +192,7 @@
 	function update_item_in_group($groupid,$itemid,$item){
 		$sql='SELECT i.itemid,i.hostid '.
 				' FROM hosts_groups hg,items i '.
-				' WHERE hg.groupid='.$groupid.
+				' WHERE hg.groupid='.zbx_dbstr($groupid).
 					' and i.key_='.zbx_dbstr($item['key_']).
 					' and hg.hostid=i.hostid';
 		$result=DBSelect($sql);
@@ -217,7 +217,7 @@
 		$del_items = array();
 		$sql='SELECT i.itemid '.
 			' FROM hosts_groups hg,items i'.
-			' WHERE hg.groupid='.$groupid.
+			' WHERE hg.groupid='.zbx_dbstr($groupid).
 				' AND i.key_='.zbx_dbstr($item["key_"]).
 				' AND hg.hostid=i.hostid';
 		$result=DBSelect($sql);
@@ -233,7 +233,7 @@
 	# Add Item definition to selected group
 
 	function add_item_to_group($groupid,$item){
-		$sql='SELECT hostid FROM hosts_groups WHERE groupid='.$groupid;
+		$sql='SELECT hostid FROM hosts_groups WHERE groupid='.zbx_dbstr($groupid);
 		$result=DBSelect($sql);
 		while($row=DBfetch($result)){
 			$item['hostid'] = $row['hostid'];
@@ -371,7 +371,7 @@
 
 		$sql = 'SELECT itemid, hostid, templateid '.
 				' FROM items '.
-				' WHERE hostid='.$item['hostid'].
+				' WHERE hostid='.zbx_dbstr($item['hostid']).
 					' AND key_='.zbx_dbstr($item['key_']);
 		$db_item = DBfetch(DBselect($sql));
 		if($db_item && (($item['templateid'] == 0) || (($db_item['templateid'] != 0) && ($item['templateid'] != 0) && ($item['templateid'] != $db_item['templateid'])))){
@@ -396,15 +396,15 @@
 					'delta,snmpv3_securityname,snmpv3_securitylevel,snmpv3_authpassphrase,'.
 					'snmpv3_privpassphrase,formula,trends,logtimefmt,valuemapid,'.
 					'delay_flex,params,ipmi_sensor,templateid,authtype,username,password,publickey,privatekey)'.
-			' VALUES ('.$itemid.','.zbx_dbstr($item['description']).','.zbx_dbstr($item['key_']).','.(!$item['hostid']? '0':$item['hostid']).','.
-						(!$item['delay']? '0':$item['delay']).','.(!$item['history']? '0':$item['history']).','.(!$item['status']? '0':$item['status']).','.(!$item['type']? '0':$item['type']).','.
-						zbx_dbstr($item['snmp_community']).','.zbx_dbstr($item['snmp_oid']).','.(!$item['value_type']? '0':$item['value_type']).','.(!$item['data_type']? '0':$item['data_type']).','.
-						zbx_dbstr($item['trapper_hosts']).','.$item['snmp_port'].','.zbx_dbstr($item['units']).','.(!$item['multiplier'] ? '0':$item['multiplier']).','.
+			' VALUES ('.$itemid.','.zbx_dbstr($item['description']).','.zbx_dbstr($item['key_']).','.(!$item['hostid']? '0':zbx_dbstr($item['hostid'])).','.
+						(!$item['delay']? '0':zbx_dbstr($item['delay'])).','.(!$item['history']? '0':zbx_dbstr($item['history'])).','.(!$item['status']? '0':zbx_dbstr($item['status'])).','.(!$item['type']? '0':zbx_dbstr($item['type'])).','.
+						zbx_dbstr($item['snmp_community']).','.zbx_dbstr($item['snmp_oid']).','.(!$item['value_type']? '0':zbx_dbstr($item['value_type'])).','.(!$item['data_type']? '0':zbx_dbstr($item['data_type'])).','.
+						zbx_dbstr($item['trapper_hosts']).','.zbx_dbstr($item['snmp_port']).','.zbx_dbstr($item['units']).','.(!$item['multiplier'] ? '0':zbx_dbstr($item['multiplier'])).','.
 						intval($item['delta']).','.zbx_dbstr($item['snmpv3_securityname']).','.intval($item['snmpv3_securitylevel']).','.
 						zbx_dbstr($item['snmpv3_authpassphrase']).','.zbx_dbstr($item['snmpv3_privpassphrase']).','.
-						zbx_dbstr($item['formula']).','.(!$item['trends'] ? '0':$item['trends']).','.zbx_dbstr($item['logtimefmt']).','.(!$item['valuemapid'] ? '0':$item['valuemapid']).','.
+						zbx_dbstr($item['formula']).','.(!$item['trends'] ? '0':zbx_dbstr($item['trends'])).','.zbx_dbstr($item['logtimefmt']).','.(!$item['valuemapid'] ? '0':zbx_dbstr($item['valuemapid'])).','.
 						zbx_dbstr($item['delay_flex']).','.zbx_dbstr($item['params']).','.
-						zbx_dbstr($item['ipmi_sensor']).','.$item['templateid'].','.intval($item['authtype']).','.
+						zbx_dbstr($item['ipmi_sensor']).','.zbx_dbstr($item['templateid']).','.intval($item['authtype']).','.
 						zbx_dbstr($item['username']).','.zbx_dbstr($item['password']).','.
 						zbx_dbstr($item['publickey']).','.zbx_dbstr($item['privatekey']).')'
 			);
@@ -416,7 +416,7 @@
 
 		foreach($item['applications'] as $key => $appid){
 			$itemappid=get_dbid('items_applications','itemappid');
-			DBexecute('INSERT INTO items_applications (itemappid,itemid,applicationid) VALUES('.$itemappid.','.$itemid.','.$appid.')');
+			DBexecute('INSERT INTO items_applications (itemappid,itemid,applicationid) VALUES('.$itemappid.','.zbx_dbstr($itemid).','.zbx_dbstr($appid).')');
 		}
 
 		info(S_ADDED_NEW_ITEM.SPACE.'"'.$host['host'].':'.$item['key_'].'"');
@@ -457,11 +457,11 @@
 			if($status != $old_status){
 /*				unset($itemids[$row['itemid']]);*/
 				if ($status==ITEM_STATUS_ACTIVE)
-					$sql='UPDATE items SET status='.$status.",error='' ".
-						' WHERE itemid='.$row['itemid'];
+					$sql='UPDATE items SET status='.zbx_dbstr($status).",error='' ".
+						' WHERE itemid='.zbx_dbstr($row['itemid']);
 				else
-					$sql='UPDATE items SET status='.$status.
-						' WHERE itemid='.$row['itemid'];
+					$sql='UPDATE items SET status='.zbx_dbstr($status).
+						' WHERE itemid='.zbx_dbstr($row['itemid']);
 
 				$result &= DBexecute($sql);
 				if ($result){
@@ -526,8 +526,8 @@
 
 		$sql = 'SELECT itemid, hostid, templateid '.
 				' FROM items '.
-				' WHERE hostid='.$item['hostid'].
-					' AND itemid<>'.$itemid.
+				' WHERE hostid='.zbx_dbstr($item['hostid']).
+					' AND itemid<>'.zbx_dbstr($itemid).
 					' AND key_='.zbx_dbstr($item['key_']);
 		$db_item = DBfetch(DBselect($sql));
 		if($db_item && (($db_item['templateid'] != 0) || ($item['templateid'] == 0))){
@@ -535,7 +535,7 @@
 			return FALSE;
 		}
 // first update child items
-		$db_tmp_items = DBselect('SELECT itemid, hostid FROM items WHERE templateid='.$itemid);
+		$db_tmp_items = DBselect('SELECT itemid, hostid FROM items WHERE templateid='.zbx_dbstr($itemid));
 		while($db_tmp_item = DBfetch($db_tmp_items)){
 			$child_item_params = $item_in_params;
 
@@ -576,54 +576,54 @@
 		}
 
 		$item_old = get_item_by_itemid($itemid);
-		DBexecute('UPDATE items SET lastlogsize=0, mtime=0 WHERE itemid='.$itemid.' AND key_<>'.zbx_dbstr($item['key_']));
+		DBexecute('UPDATE items SET lastlogsize=0, mtime=0 WHERE itemid='.zbx_dbstr($itemid).' AND key_<>'.zbx_dbstr($item['key_']));
 
 		if($upd_app){
-			$result = DBexecute('DELETE FROM items_applications WHERE itemid='.$itemid);
+			$result = DBexecute('DELETE FROM items_applications WHERE itemid='.zbx_dbstr($itemid));
 			foreach($item['applications'] as $appid){
 				$itemappid=get_dbid('items_applications','itemappid');
-				DBexecute('INSERT INTO items_applications (itemappid,itemid,applicationid) VALUES ('.$itemappid.','.$itemid.','.$appid.')');
+				DBexecute('INSERT INTO items_applications (itemappid,itemid,applicationid) VALUES ('.$itemappid.','.zbx_dbstr($itemid).','.zbx_dbstr($appid).')');
 			}
 		}
 
 		if($item['status'] == ITEM_STATUS_ACTIVE)
-			DBexecute("UPDATE items SET error='' WHERE itemid=".$itemid.' and status<>'.$item['status']);
+			DBexecute("UPDATE items SET error='' WHERE itemid=".zbx_dbstr($itemid).' and status<>'.zbx_dbstr($item['status']));
 
 		$result=DBexecute(
 			'UPDATE items '.
 			' SET description='.zbx_dbstr($item['description']).','.
 				'key_='.zbx_dbstr($item['key_']).','.
-				'hostid='.$item['hostid'].','.
-				'delay='.$item['delay'].','.
-				'history='.$item['history'].','.
-				'type='.$item['type'].','.
+				'hostid='.zbx_dbstr($item['hostid']).','.
+				'delay='.zbx_dbstr($item['delay']).','.
+				'history='.zbx_dbstr($item['history']).','.
+				'type='.zbx_dbstr($item['type']).','.
 				'snmp_community='.zbx_dbstr($item['snmp_community']).','.
 				'snmp_oid='.zbx_dbstr($item['snmp_oid']).','.
-				'value_type='.$item['value_type'].','.
-				'data_type='.$item['data_type'].','.
+				'value_type='.zbx_dbstr($item['value_type']).','.
+				'data_type='.zbx_dbstr($item['data_type']).','.
 				'trapper_hosts='.zbx_dbstr($item['trapper_hosts']).','.
-				'snmp_port='.$item['snmp_port'].','.
+				'snmp_port='.zbx_dbstr($item['snmp_port']).','.
 				'units='.zbx_dbstr($item['units']).','.
-				'multiplier='.$item['multiplier'].','.
-				'delta='.$item['delta'].','.
+				'multiplier='.zbx_dbstr($item['multiplier']).','.
+				'delta='.zbx_dbstr($item['delta']).','.
 				'snmpv3_securityname='.zbx_dbstr($item['snmpv3_securityname']).','.
-				'snmpv3_securitylevel='.$item['snmpv3_securitylevel'].','.
+				'snmpv3_securitylevel='.zbx_dbstr($item['snmpv3_securitylevel']).','.
 				'snmpv3_authpassphrase='.($item['snmpv3_securitylevel'] == ITEM_SNMPV3_SECURITYLEVEL_AUTHPRIV || $item['snmpv3_securitylevel'] == ITEM_SNMPV3_SECURITYLEVEL_AUTHNOPRIV ? zbx_dbstr($item['snmpv3_authpassphrase']) : "''").','.
 				'snmpv3_privpassphrase='.($item['snmpv3_securitylevel'] == ITEM_SNMPV3_SECURITYLEVEL_AUTHPRIV ? zbx_dbstr($item['snmpv3_privpassphrase']) : "''").','.
 				'formula='.zbx_dbstr($item['formula']).','.
-				'trends='.$item['trends'].','.
+				'trends='.zbx_dbstr($item['trends']).','.
 				'logtimefmt='.zbx_dbstr($item['logtimefmt']).','.
-				'valuemapid='.$item['valuemapid'].','.
+				'valuemapid='.zbx_dbstr($item['valuemapid']).','.
 				'delay_flex='.zbx_dbstr($item['delay_flex']).','.
 				'params='.zbx_dbstr($item['params']).','.
 				'ipmi_sensor='.zbx_dbstr($item['ipmi_sensor']).','.
-				'templateid='.$item['templateid'].','.
-				'authtype='.$item['authtype'].','.
+				'templateid='.zbx_dbstr($item['templateid']).','.
+				'authtype='.zbx_dbstr($item['authtype']).','.
 				'username='.zbx_dbstr($item['username']).','.
 				'password='.zbx_dbstr($item['password']).','.
 				'publickey='.zbx_dbstr($item['publickey']).','.
 				'privatekey='.zbx_dbstr($item['privatekey']).
-			' WHERE itemid='.$itemid);
+			' WHERE itemid='.zbx_dbstr($itemid));
 
 		if ($result){
 			$item_new = get_item_by_itemid($itemid);
@@ -735,7 +735,7 @@
 			}
 
 			if ($unlink_mode) {
-				if (DBexecute('UPDATE items SET templateid=0 WHERE itemid='.$db_item["itemid"])) {
+				if (DBexecute('UPDATE items SET templateid=0 WHERE itemid='.zbx_dbstr($db_item["itemid"]))) {
 					info(sprintf(S_ITEM_UNLINKED, $host['host'].':'.$db_item["key_"]));
 				}
 			}
@@ -861,7 +861,7 @@
 	}
 
 	function get_item_by_itemid($itemid){
-		$row = DBfetch(DBselect('select * from items where itemid='.$itemid));
+		$row = DBfetch(DBselect('select * from items where itemid='.zbx_dbstr($itemid)));
 		if($row){
 			return	$row;
 		}
@@ -876,7 +876,7 @@
 					'formula,trends,logtimefmt,valuemapid,delay_flex,params,ipmi_sensor,templateid,'.
 					'authtype,username,password,publickey,privatekey '.
 			' FROM items '.
-			' WHERE itemid='.$itemid;
+			' WHERE itemid='.zbx_dbstr($itemid);
 		$row = DBfetch(DBselect($sql));
 		if($row){
 			return	$row;
@@ -913,7 +913,7 @@
 		if(isset($itemid)){
 			$sql = 'SELECT src.* '.
 							' FROM items src, items dest '.
-							' WHERE dest.itemid='.$itemid.
+							' WHERE dest.itemid='.zbx_dbstr($itemid).
 								' AND src.key_=dest.key_ '.
 								' AND '.DBcondition('src.hostid',$dest_hostids);
 
@@ -1006,7 +1006,7 @@
 
 		foreach ($itemids as $id) {	/* The section should be improved */
 			$item_old = get_item_by_itemid($id);
-			$result = DBexecute('DELETE FROM items WHERE itemid='.$id);
+			$result = DBexecute('DELETE FROM items WHERE itemid='.zbx_dbstr($id));
 			if ($result)
 				add_audit_ext(AUDIT_ACTION_DELETE, AUDIT_RESOURCE_ITEM, $id, $item_old['description'], 'items', NULL, NULL);
 			else
@@ -1292,7 +1292,7 @@
 
 		foreach($applications as $appid){
 			$db_apps = DBselect("select a1.applicationid from applications a1, applications a2".
-					" where a1.name=a2.name and a1.hostid=".$hostid." and a2.applicationid=".$appid);
+					" where a1.name=a2.name and a1.hostid=".zbx_dbstr($hostid)." and a2.applicationid=".zbx_dbstr($appid));
 			$db_app = DBfetch($db_apps);
 			if(!$db_app) continue;
 			array_push($child_applications,$db_app["applicationid"]);
@@ -1463,18 +1463,18 @@
 		}
 
 		if($last == 0){
-			$sql = 'select value from '.$table.' where itemid='.$db_item['itemid'].' and clock<='.$clock.
+			$sql = 'select value from '.$table.' where itemid='.zbx_dbstr($db_item['itemid']).' and clock<='.zbx_dbstr($clock).
 					' order by itemid,clock desc';
 			$row = DBfetch(DBselect($sql, 1));
 			if($row)
 				$value = $row["value"];
 		}
 		else{
-			$sql = "select max(clock) as clock from $table where itemid=".$db_item["itemid"];
+			$sql = "select max(clock) as clock from $table where itemid=".zbx_dbstr($db_item["itemid"]);
 			$row = DBfetch(DBselect($sql));
 			if($row && !is_null($row["clock"])){
 				$clock = $row["clock"];
-				$sql = "select value from $table where itemid=".$db_item["itemid"]." and clock=$clock";
+				$sql = "select value from $table where itemid=".zbx_dbstr($db_item["itemid"]).' and clock='.zbx_dbstr($clock);
 				$row = DBfetch(DBselect($sql, 1));
 				if($row)
 					$value = $row["value"];
Index: frontends/php/include/services.inc.php
===================================================================
--- frontends/php/include/services.inc.php	(revision 38884)
+++ frontends/php/include/services.inc.php	(working copy)
@@ -27,10 +27,6 @@
 			}
 		}
 
-		if (is_null($triggerid) || $triggerid == 0) {
-			$triggerid = 'NULL';
-		}
-
 		$serviceid = get_dbid('services', 'serviceid');
 
 		// removes all links with current serviceid
@@ -51,9 +47,16 @@
 			return false;
 		}
 
+		if (is_null($triggerid) || $triggerid == 0) {
+			$triggerid = 'NULL';
+		}
+		else {
+			$triggerid = zbx_dbstr($triggerid);
+		}
+
 		$result = DBexecute('INSERT INTO services (serviceid,name,status,triggerid,algorithm,showsla,goodsla,sortorder)'.
 							' VALUES ('.$serviceid.','.zbx_dbstr($name).',0,'.$triggerid.','.zbx_dbstr($algorithm).
-								','.$showsla.','.zbx_dbstr($goodsla).','.$sortorder.')');
+								','.zbx_dbstr($showsla).','.zbx_dbstr($goodsla).','.zbx_dbstr($sortorder).')');
 		if (!$result) {
 			return false;
 		}
@@ -61,12 +64,12 @@
 		// updating status to all services by the dependency
 		update_services_status_all();
 
-		DBExecute('DELETE FROM services_times WHERE serviceid='.$serviceid);
+		DBExecute('DELETE FROM services_times WHERE serviceid='.zbx_dbstr($serviceid));
 
 		foreach ($service_times as $val) {
 			$timeid = get_dbid('services_times', 'timeid');
 			$result = DBexecute('INSERT INTO services_times (timeid,serviceid,type,ts_from,ts_to,note)'.
-				' values ('.$timeid.','.$serviceid.','.$val['type'].','.$val['from'].','.$val['to'].','.zbx_dbstr($val['note']).')');
+				' values ('.$timeid.','.zbx_dbstr($serviceid).','.zbx_dbstr($val['type']).','.zbx_dbstr($val['from']).','.zbx_dbstr($val['to']).','.zbx_dbstr($val['note']).')');
 			if (!$result) {
 				delete_service($serviceid);
 				return false;
@@ -104,12 +107,15 @@
 		if (is_null($triggerid) || $triggerid == 0) {
 			$triggerid = 'NULL';
 		}
+		else {
+			$triggerid = zbx_dbstr($triggerid);
+		}
 
 		$result = DBexecute('UPDATE services'.
 							' SET name='.zbx_dbstr($name).
-								',triggerid='.$triggerid.',status=0,algorithm='.$algorithm.
-								',showsla='.$showsla.',goodsla='.$goodsla.',sortorder='.$sortorder.
-							' WHERE serviceid='.$serviceid);
+								',triggerid='.$triggerid.',status=0,algorithm='.zbx_dbstr($algorithm).
+								',showsla='.zbx_dbstr($showsla).',goodsla='.zbx_dbstr($goodsla).',sortorder='.zbx_dbstr($sortorder).
+							' WHERE serviceid='.zbx_dbstr($serviceid));
 
 		// updating status to all services by the dependency
 		update_services_status_all();
@@ -119,7 +125,7 @@
 		foreach ($service_times as $val) {
 			$timeid = get_dbid('services_times', 'timeid');
 			DBexecute('INSERT INTO services_times (timeid,serviceid,type,ts_from,ts_to,note)'.
-				' VALUES ('.$timeid.','.$serviceid.','.$val['type'].','.$val['from'].','.$val['to'].','.zbx_dbstr($val['note']).')');
+				' VALUES ('.$timeid.','.zbx_dbstr($serviceid).','.zbx_dbstr($val['type']).','.zbx_dbstr($val['from']).','.zbx_dbstr($val['to']).','.zbx_dbstr($val['note']).')');
 		}
 
 		return $result;
@@ -131,7 +137,7 @@
 							' WHERE h.hostid=i.hostid'.
 								' AND i.itemid=f.itemid'.
 								' AND f.triggerid=t.triggerid'.
-								' AND h.hostid='.$hostid.
+								' AND h.hostid='.zbx_dbstr($hostid).
 								' AND '.DBin_node('t.triggerid', false)
 							);
 		while ($row = DBfetch($result)) {
@@ -142,7 +148,7 @@
 	}
 
 	function is_service_hardlinked($serviceid) {
-		$row = DBfetch(DBselect('SELECT COUNT(*) as cnt FROM services_links sl WHERE sl.servicedownid='.$serviceid.' and sl.soft=0'));
+		$row = DBfetch(DBselect('SELECT COUNT(*) as cnt FROM services_links sl WHERE sl.servicedownid='.zbx_dbstr($serviceid).' and sl.soft=0'));
 		if ($row && $row['cnt'] > 0) {
 			return true;
 		}
@@ -171,7 +177,7 @@
 
 			$result = DBselect('SELECT s.status'.
 					' FROM services s,services_links l'.
-					' WHERE l.serviceupid='.$serviceid.
+					' WHERE l.serviceupid='.zbx_dbstr($serviceid).
 						' AND s.serviceid=l.servicedownid'.
 					' ORDER BY s.status '.$sort_order);
 			if ($row = DBfetch($result)) {
@@ -187,22 +193,22 @@
 	 *                                                                            *
 	 ******************************************************************************/
 	function delete_service($serviceid) {
-		$sql = 'DELETE FROM services_links WHERE servicedownid='.$serviceid.' OR serviceupid='.$serviceid;
+		$sql = 'DELETE FROM services_links WHERE servicedownid='.zbx_dbstr($serviceid).' OR serviceupid='.zbx_dbstr($serviceid);
 		if (!$result = DBexecute($sql)) {
 			return $result;
 		}
 
-		$sql = 'DELETE FROM services WHERE serviceid='.$serviceid;
+		$sql = 'DELETE FROM services WHERE serviceid='.zbx_dbstr($serviceid);
 		if (!$result = DBexecute($sql)) {
 			return $result;
 		}
 
-		$sql = 'DELETE FROM service_alarms WHERE serviceid='.$serviceid;
+		$sql = 'DELETE FROM service_alarms WHERE serviceid='.zbx_dbstr($serviceid);
 		if (!$result = DBexecute($sql)) {
 			return $result;
 		}
 
-		$sql = 'DELETE FROM services_times WHERE serviceid='.$serviceid;
+		$sql = 'DELETE FROM services_times WHERE serviceid='.zbx_dbstr($serviceid);
 		if (!$result = DBexecute($sql)) {
 			return $result;
 		}
@@ -225,7 +231,7 @@
 	 */
 	function clear_parents_from_trigger($serviceid = 0) {
 		if ($serviceid != 0) {
-			DBexecute('UPDATE services SET triggerid=NULL WHERE serviceid='.$serviceid);
+			DBexecute('UPDATE services SET triggerid=NULL WHERE serviceid='.zbx_dbstr($serviceid));
 			return null;
 		}
 
@@ -235,7 +241,7 @@
 								' AND NOT s.triggerid IS NULL'.
 							' GROUP BY s.serviceid');
 		while ($row = DBfetch($result)) {
-			DBexecute('UPDATE services SET triggerid=NULL WHERE serviceid='.$row['serviceid']);
+			DBexecute('UPDATE services SET triggerid=NULL WHERE serviceid='.zbx_dbstr($row['serviceid']));
 		}
 	}
 
@@ -252,7 +258,7 @@
 			}
 		}
 
-		$result = DBselect('SELECT sl.serviceupid FROM services_links sl WHERE sl.servicedownid='.$serviceid2.' and sl.soft=0');
+		$result = DBselect('SELECT sl.serviceupid FROM services_links sl WHERE sl.servicedownid='.zbx_dbstr($serviceid2).' and sl.soft=0');
 		while ($row = DBfetch($result)) {
 			if (does_service_depend_on_the_service($serviceid, $row['serviceupid']) == true) {
 				return true;
@@ -274,7 +280,7 @@
 
 		$linkid = get_dbid('services_links', 'linkid');
 
-		$result = DBexecute('INSERT INTO services_links (linkid,servicedownid,serviceupid,soft) values ('.$linkid.','.$servicedownid.','.$serviceupid.','.$softlink.')');
+		$result = DBexecute('INSERT INTO services_links (linkid,servicedownid,serviceupid,soft) values ('.$linkid.','.zbx_dbstr($servicedownid).','.zbx_dbstr($serviceupid).','.zbx_dbstr($softlink).')');
 
 		if (!$result) {
 			return $result;
@@ -284,7 +290,7 @@
 	}
 
 	function remove_service_links($serviceid) {
-		DBExecute('DELETE FROM services_links WHERE serviceupid='.$serviceid.' OR (servicedownid='.$serviceid.' AND soft<>1)');
+		DBExecute('DELETE FROM services_links WHERE serviceupid='.zbx_dbstr($serviceid).' OR (servicedownid='.zbx_dbstr($serviceid).' AND soft<>1)');
 	}
 
 	function get_last_service_value($serviceid, $clock) {
@@ -293,8 +299,8 @@
 		$result = DBselect(
 			'SELECT MAX(sa.clock) AS clock'.
 			' FROM service_alarms sa'.
-			' WHERE sa.serviceid='.$serviceid.
-				' AND sa.clock<'.$clock
+			' WHERE sa.serviceid='.zbx_dbstr($serviceid).
+				' AND sa.clock<'.zbx_dbstr($clock)
 		);
 		$row = DBfetch($result);
 		if ($row && !is_null($row['clock'])) {
@@ -302,8 +308,8 @@
 			$result2 = DBselect(
 				'SELECT sa.value'.
 				' FROM service_alarms sa'.
-				' WHERE sa.serviceid='.$serviceid.
-					' AND sa.clock='.$row['clock'].
+				' WHERE sa.serviceid='.zbx_dbstr($serviceid).
+					' AND sa.clock='.zbx_dbstr($row['clock']).
 				' ORDER BY sa.servicealarmid DESC', 1
 			);
 			if ($row2 = DBfetch($result2)) {
@@ -370,7 +376,7 @@
 		$result = DBselect(
 			'SELECT sa.servicealarmid,sa.clock,sa.value'.
 			' FROM service_alarms sa'.
-			' WHERE sa.serviceid='.$serviceid.
+			' WHERE sa.serviceid='.zbx_dbstr($serviceid).
 				' AND sa.clock BETWEEN '.$period_start.' AND '.$period_end.
 			' ORDER BY sa.clock,sa.servicealarmid'
 		);
@@ -385,7 +391,7 @@
 			'SELECT st.ts_from,st.ts_to'.
 			' FROM services_times st'.
 			' WHERE st.type='.SERVICE_TIME_TYPE_UPTIME.
-				' AND st.serviceid='.$serviceid
+				' AND st.serviceid='.zbx_dbstr($serviceid)
 		);
 		while ($row = DBfetch($result)) {
 			expandPeriodicalServiceTimes($data, $period_start, $period_end, $row['ts_from'], $row['ts_to'], 'ut');
@@ -399,7 +405,7 @@
 			'SELECT st.ts_from,st.ts_to'.
 			' FROM services_times st'.
 			' WHERE st.type='.SERVICE_TIME_TYPE_DOWNTIME.
-				' AND st.serviceid='.$serviceid
+				' AND st.serviceid='.zbx_dbstr($serviceid)
 		);
 		while ($row = DBfetch($result)) {
 			expandPeriodicalServiceTimes($data, $period_start, $period_end, $row['ts_from'], $row['ts_to'], 'dt');
@@ -410,9 +416,9 @@
 			'SELECT st.ts_from,st.ts_to'.
 			' FROM services_times st'.
 			' WHERE st.type='.SERVICE_TIME_TYPE_ONETIME_DOWNTIME.
-				' AND st.ts_to>='.$period_start.
-				' AND st.ts_from<='.$period_end.
-				' AND st.serviceid='.$serviceid
+				' AND st.ts_to>='.zbx_dbstr($period_start).
+				' AND st.ts_from<='.zbx_dbstr($period_end).
+				' AND st.serviceid='.zbx_dbstr($serviceid)
 		);
 		while ($row = DBfetch($result)) {
 			if ($row['ts_from'] < $period_start) {
@@ -553,7 +559,7 @@
 
 		$query = 'SELECT sl.servicedownid'.
 				' FROM services_links sl'.
-				' WHERE sl.serviceupid='.$serviceid.($soft ? '' : ' AND sl.soft<>1');
+				' WHERE sl.serviceupid='.zbx_dbstr($serviceid).($soft ? '' : ' AND sl.soft<>1');
 
 		$result = DBselect($query);
 		while ($row = DBfetch($result)) {
@@ -653,7 +659,7 @@
 		$result = DBselect('SELECT l.serviceupid,s.algorithm'.
 							' FROM services_links l,services s'.
 							' WHERE s.serviceid=l.serviceupid'.
-								' AND l.servicedownid='.$serviceid
+								' AND l.servicedownid='.zbx_dbstr($serviceid)
 							);
 		while ($row = DBfetch($result)) {
 			$serviceupid = $row['serviceupid'];
@@ -662,7 +668,7 @@
 			if ($algorithm == SERVICE_ALGORITHM_MAX || $algorithm == SERVICE_ALGORITHM_MIN) {
 				$status = get_service_status($serviceupid, $algorithm);
 				add_service_alarm($serviceupid, $status, time());
-				DBexecute('UPDATE services SET status='.$status.' WHERE serviceid='.$serviceupid);
+				DBexecute('UPDATE services SET status='.zbx_dbstr($status).' WHERE serviceid='.zbx_dbstr($serviceupid));
 			}
 			elseif ($algorithm != SERVICE_ALGORITHM_NONE) {
 				error(S_UNKNOWN_CALC_ALGORITHM_OF_SERVICE_STATUS.SPACE.'['.$algorithm.']');
@@ -670,7 +676,7 @@
 			}
 		}
 
-		$result = DBselect('SELECT sl.serviceupid FROM services_links sl WHERE sl.servicedownid='.$serviceid);
+		$result = DBselect('SELECT sl.serviceupid FROM services_links sl WHERE sl.servicedownid='.zbx_dbstr($serviceid));
 		while ($row = DBfetch($result)) {
 			$serviceupid = $row['serviceupid'];
 			update_services_rec($serviceupid);	// ATTENTION: recursion!!!
@@ -695,9 +701,9 @@
 	 *                                                                            *
 	 ******************************************************************************/
 	function update_services($triggerid, $status) {
-		DBexecute('UPDATE services SET status='.$status.' WHERE triggerid='.$triggerid);
+		DBexecute('UPDATE services SET status='.zbx_dbstr($status).' WHERE triggerid='.zbx_dbstr($triggerid));
 
-		$result = DBselect('SELECT s.serviceid FROM services s WHERE s.triggerid='.$triggerid);
+		$result = DBselect('SELECT s.serviceid FROM services s WHERE s.triggerid='.zbx_dbstr($triggerid));
 		while ($row = DBfetch($result)) {
 			add_service_alarm($row['serviceid'], $status, time());
 			update_services_rec($row['serviceid']);
@@ -721,7 +727,7 @@
 							' WHERE s.serviceid NOT IN (select distinct sl.serviceupid from services_links sl)');
 		while ($row = DBfetch($result)) {
 			$status = get_service_status($row['serviceid'], $row['algorithm'], $row['triggerid']);
-			DBexecute('UPDATE services SET status='.$status.' WHERE serviceid='.$row['serviceid']);
+			DBexecute('UPDATE services SET status='.zbx_dbstr($status).' WHERE serviceid='.zbx_dbstr($row['serviceid']));
 			add_service_alarm($row['serviceid'], $status, time());
 		}
 
@@ -742,7 +748,7 @@
 	function latest_service_alarm($serviceid, $status) {
 		$result = DBselect('SELECT sa.servicealarmid,sa.value'.
 							' FROM service_alarms sa'.
-							' WHERE sa.serviceid='.$serviceid.
+							' WHERE sa.serviceid='.zbx_dbstr($serviceid).
 							' ORDER BY sa.servicealarmid DESC', 1);
 		$row = DBfetch($result);
 		if ($row && $row['value'] == $status) {
@@ -760,6 +766,6 @@
 		if (latest_service_alarm($serviceid, $status)) {
 			return true;
 		}
-		return DBexecute('INSERT INTO service_alarms (servicealarmid,serviceid,clock,value) VALUES ('.get_dbid('service_alarms', 'servicealarmid').','.$serviceid.','.$clock.','.$status.')');
+		return DBexecute('INSERT INTO service_alarms (servicealarmid,serviceid,clock,value) VALUES ('.get_dbid('service_alarms', 'servicealarmid').','.zbx_dbstr($serviceid).','.zbx_dbstr($clock).','.zbx_dbstr($status).')');
 	}
 ?>
Index: frontends/php/include/profiles.inc.php
===================================================================
--- frontends/php/include/profiles.inc.php	(revision 38884)
+++ frontends/php/include/profiles.inc.php	(working copy)
@@ -134,8 +134,8 @@
 			'userid' => $USER_DETAILS['userid'],
 			'idx' => zbx_dbstr($idx),
 			$value_type => ($value_type == 'value_str') ? zbx_dbstr($value) : $value,
-			'type' => $type,
-			'idx2' => $idx2
+			'type' => zbx_dbstr($type),
+			'idx2' => zbx_dbstr($idx2)
 		);
 
 		$sql = 'INSERT INTO profiles ('.implode(', ', array_keys($values)).') VALUES ('.implode(', ', $values).')';
@@ -156,8 +156,8 @@
 		$value = ($value_type == 'value_str') ? zbx_dbstr($value) : $value;
 
 		$sql = 'UPDATE profiles SET '.
-					$value_type.'='.$value.','.
-					' type='.$type.
+					$value_type.'='.zbx_dbstr($value).','.
+					' type='.zbx_dbstr($type).
 				' WHERE userid='.$USER_DETAILS['userid'].
 					' AND idx='.zbx_dbstr($idx).
 					$sql_cond;
@@ -382,7 +382,7 @@
 		'profileid' => get_dbid('profiles', 'profileid'),
 		'userid' => $USER_DETAILS['userid'],
 		'idx' => zbx_dbstr($favobj),
-		'value_id' =>  $favid,
+		'value_id' => zbx_dbstr($favid),
 		'type' => PROFILE_TYPE_ID
 	);
 	if(!is_null($source)) $values['source'] = zbx_dbstr($source);
@@ -402,7 +402,7 @@
 	$sql = 'DELETE FROM profiles '.
 		' WHERE userid='.$USER_DETAILS['userid'].
 			' AND idx='.zbx_dbstr($favobj).
-			(($favid > 0) ? ' AND value_id='.$favid : '').
+			(($favid > 0) ? ' AND value_id='.zbx_dbstr($favid) : '').
 			(is_null($source) ? '' : ' AND source='.zbx_dbstr($source));
 
 	return DBexecute($sql);
Index: frontends/php/include/graphs.inc.php
===================================================================
--- frontends/php/include/graphs.inc.php	(revision 38884)
+++ frontends/php/include/graphs.inc.php	(working copy)
@@ -138,7 +138,7 @@
 
 		$sql = 'SELECT MAX(g.graphtype) as graphtype, MIN(gi.yaxisside) as yaxissidel, MAX(gi.yaxisside) as yaxissider, MAX(g.height) as height'.
 				' FROM graphs g, graphs_items gi '.
-				' WHERE g.graphid='.$graphid.
+				' WHERE g.graphid='.zbx_dbstr($graphid).
 					' AND gi.graphid=g.graphid ';
 		$res = DBselect($sql);
 		if($graph=DBfetch($res)){
@@ -172,7 +172,7 @@
 				' FROM graphs g, graphs_items gi, items i '.
 				' WHERE g.graphid=gi.graphid '.
 					' AND gi.itemid=i.itemid '.
-					' AND i.hostid='.$hostid;
+					' AND i.hostid='.zbx_dbstr($hostid);
 	return DBselect($sql);
 	}
 
@@ -189,13 +189,13 @@
 							' FROM graphs_items gi, items i, hosts h'.
 							' WHERE h.hostid=i.hostid '.
 								' AND gi.itemid=i.itemid '.
-								' AND gi.graphid='.$graphid);
+								' AND gi.graphid='.zbx_dbstr($graphid));
 	}
 
 	function get_graphitems_by_graphid($graphid){
 		return DBselect('SELECT * '.
 					' FROM graphs_items '.
-					' WHERE graphid='.$graphid.
+					' WHERE graphid='.zbx_dbstr($graphid).
 					' ORDER BY itemid,drawtype,sortorder,color,yaxisside');
 	}
 
@@ -216,7 +216,7 @@
 		$itemids = array();
 		$sql = 'SELECT DISTINCT gi.itemid '.
 				' FROM graphs_items gi '.
-				' WHERE gi.graphid='.$graphid;
+				' WHERE gi.graphid='.zbx_dbstr($graphid);
 		$res = DBselect($sql);
 		while($item = DBfetch($res)){
 			$itemids[$item['itemid']] = $item['itemid'];
@@ -310,7 +310,7 @@
 
 	function get_graph_by_graphid($graphid){
 
-		$result=DBselect("SELECT * FROM graphs WHERE graphid=$graphid");
+		$result=DBselect('SELECT * FROM graphs WHERE graphid='.zbx_dbstr($graphid));
 		$row=DBfetch($result);
 		if($row){
 			return	$row;
@@ -343,9 +343,9 @@
 		foreach($gitems as $gitem){
 			$sql = 'SELECT src.itemid, dest.key_ '.
 					' FROM items src, items dest '.
-					' WHERE dest.itemid='.$gitem['itemid'].
+					' WHERE dest.itemid='.zbx_dbstr($gitem['itemid']).
 						' AND src.key_=dest.key_ '.
-						' AND src.hostid='.$dest_hostid;
+						' AND src.hostid='.zbx_dbstr($dest_hostid);
 			$db_item = DBfetch(DBselect($sql));
 			if (!$db_item && $error){
 				$item = get_item_by_itemid($gitem['itemid']);
@@ -386,8 +386,11 @@
 
 		$result=DBexecute('INSERT INTO graphs '.
 			' (graphid,name,width,height,ymin_type,ymax_type,yaxismin,yaxismax,ymin_itemid,ymax_itemid,templateid,show_work_period,show_triggers,graphtype,show_legend,show_3d,percent_left,percent_right) '.
-			" VALUES ($graphid,".zbx_dbstr($name).",$width,$height,$ymin_type,$ymax_type,$yaxismin,$yaxismax,$ymin_itemid,$ymax_itemid,".
-			" $templateid,$showworkperiod,$showtriggers,$graphtype,$legend,$graph3d,$percent_left,$percent_right)");
+			' VALUES ('.$graphid.','.zbx_dbstr($name).','.zbx_dbstr($width).','.zbx_dbstr($height).','.
+				zbx_dbstr($ymin_type).','.zbx_dbstr($ymax_type).','.zbx_dbstr($yaxismin).','.zbx_dbstr($yaxismax).','.
+				zbx_dbstr($ymin_itemid).','.zbx_dbstr($ymax_itemid).','.zbx_dbstr($templateid).','.
+				zbx_dbstr($showworkperiod).','.zbx_dbstr($showtriggers).','.zbx_dbstr($graphtype).','.zbx_dbstr($legend).','.
+				zbx_dbstr($graph3d).','.zbx_dbstr($percent_left).','.zbx_dbstr($percent_right));
 
 		return ( $result ? $graphid : $result);
 	}
@@ -507,28 +510,28 @@
 
 		$sql = 'UPDATE graphs SET '.
 				'name='.zbx_dbstr($name).','.
-				'width='.$width.','.
-				'height='.$height.','.
-				'ymin_type='.$ymin_type.','.
-				'ymax_type='.$ymax_type.','.
-				'yaxismin='.$yaxismin.','.
-				'yaxismax='.$yaxismax.','.
-				'ymin_itemid='.$ymin_itemid.','.
-				'ymax_itemid='.$ymax_itemid.','.
-				'templateid='.$templateid.','.
-				'show_work_period='.$showworkperiod.','.
-				'show_triggers='.$showtriggers.','.
-				'graphtype='.$graphtype.','.
-				'show_legend='.$legend.','.
-				'show_3d='.$graph3d.','.
-				'percent_left='.$percent_left.','.
-				'percent_right='.$percent_right.
-			' WHERE graphid='.$graphid;
+				'width='.zbx_dbstr($width).','.
+				'height='.zbx_dbstr($height).','.
+				'ymin_type='.zbx_dbstr($ymin_type).','.
+				'ymax_type='.zbx_dbstr($ymax_type).','.
+				'yaxismin='.zbx_dbstr($yaxismin).','.
+				'yaxismax='.zbx_dbstr($yaxismax).','.
+				'ymin_itemid='.zbx_dbstr($ymin_itemid).','.
+				'ymax_itemid='.zbx_dbstr($ymax_itemid).','.
+				'templateid='.zbx_dbstr($templateid).','.
+				'show_work_period='.zbx_dbstr($showworkperiod).','.
+				'show_triggers='.zbx_dbstr($showtriggers).','.
+				'graphtype='.zbx_dbstr($graphtype).','.
+				'show_legend='.zbx_dbstr($legend).','.
+				'show_3d='.zbx_dbstr($graph3d).','.
+				'percent_left='.zbx_dbstr($percent_left).','.
+				'percent_right='.zbx_dbstr($percent_right).
+			' WHERE graphid='.zbx_dbstr($graphid);
 
 		if($result = DBexecute($sql)){
 			if($g_graph['graphtype'] != $graphtype && $graphtype == GRAPH_TYPE_STACKED){
 				$result = DBexecute('UPDATE graphs_items SET calc_fnc='.CALC_FNC_AVG.',drawtype=1,type='.GRAPH_ITEM_SIMPLE.
-					' WHERE graphid='.$graphid);
+					' WHERE graphid='.zbx_dbstr($graphid));
 			}
 		}
 		return $result;
@@ -600,7 +603,7 @@
 			}
 		}
 
-		DBexecute('DELETE FROM graphs_items WHERE graphid='.$graphid);
+		DBexecute('DELETE FROM graphs_items WHERE graphid='.zbx_dbstr($graphid));
 
 		foreach($gitems as $gitem){
 			if (!$result = add_item_to_graph(
@@ -740,8 +743,8 @@
 
 		$result = DBexecute('insert into graphs_items'.
 			' (gitemid,graphid,itemid,color,drawtype,sortorder,yaxisside,calc_fnc,type,periods_cnt)'.
-			' values ('.$gitemid.','.$graphid.','.$itemid.','.zbx_dbstr($color).','.$drawtype.','.
-			$sortorder.','.$yaxisside.','.$calc_fnc.','.$type.','.$periods_cnt.')');
+			' values ('.$gitemid.','.zbx_dbstr($graphid).','.zbx_dbstr($itemid).','.zbx_dbstr($color).','.zbx_dbstr($drawtype).','.
+			zbx_dbstr($sortorder).','.zbx_dbstr($yaxisside).','.zbx_dbstr($calc_fnc).','.zbx_dbstr($type).','.zbx_dbstr($periods_cnt).')');
 
 		return ( $result ? $gitemid : $result );
 	}
@@ -780,7 +783,7 @@
 			}
 
 			if ($unlink_mode) {
-				if (DBexecute('UPDATE graphs SET templateid=0 WHERE graphid='.$db_graph['graphid'])) {
+				if (DBexecute('UPDATE graphs SET templateid=0 WHERE graphid='.zbx_dbstr($db_graph['graphid']))) {
 					info(S_GRAPH.SPACE.'"'.$host['host'].':'.$db_graph['name'].'"'.SPACE.S_UNLINKED_SMALL);
 				}
 			}
Index: frontends/php/include/db.inc.php
===================================================================
--- frontends/php/include/db.inc.php	(revision 38884)
+++ frontends/php/include/db.inc.php	(working copy)
@@ -129,7 +129,7 @@
 						);
 						db2_set_option($DB['DB'], $options, 1);
 						if(isset($DB['SCHEMA']) && ($DB['SCHEMA'] != '')){
-							DBexecute("SET CURRENT SCHEMA='".$DB['SCHEMA']."'");
+							DBexecute('SET CURRENT SCHEMA='.zbx_dbstr($DB['SCHEMA']));
 						}
 					}
 
Index: frontends/php/include/scripts.inc.php
===================================================================
--- frontends/php/include/scripts.inc.php	(revision 38884)
+++ frontends/php/include/scripts.inc.php	(working copy)
@@ -1,7 +1,7 @@
 <?php
 
 function get_script_by_scriptid($scriptid){
-	$sql = 'SELECT * FROM scripts WHERE scriptid='.$scriptid;
+	$sql = 'SELECT * FROM scripts WHERE scriptid='.zbx_dbstr($scriptid);
 
 	$rows = false;
 	if($res = DBSelect($sql)){
@@ -13,7 +13,7 @@
 function add_script($name,$command,$usrgrpid,$groupid,$access){
 	$scriptid = get_dbid('scripts','scriptid');
 	$sql = 'INSERT INTO scripts (scriptid,name,command,usrgrpid,groupid,host_access) '.
-				" VALUES ($scriptid,".zbx_dbstr($name).','.zbx_dbstr($command).",$usrgrpid,$groupid,$access)";
+				' VALUES ('.$scriptid.','.zbx_dbstr($name).','.zbx_dbstr($command).','.zbx_dbstr($usrgrpid).','.zbx_dbstr($groupid).','.zbx_dbstr($access).')';
 	$result = DBexecute($sql);
 	if($result){
 		$result = $scriptid;
@@ -35,18 +35,18 @@
 	$sql = 'UPDATE scripts SET '.
 				' name='.zbx_dbstr($name).
 				' ,command='.zbx_dbstr($command).
-				' ,usrgrpid='.$usrgrpid.
-				' ,groupid='.$groupid.
-				' ,host_access='.$access.
-			' WHERE scriptid='.$scriptid;
+				' ,usrgrpid='.zbx_dbstr($usrgrpid).
+				' ,groupid='.zbx_dbstr($groupid).
+				' ,host_access='.zbx_dbstr($access).
+			' WHERE scriptid='.zbx_dbstr($scriptid);
 
 	$result = DBexecute($sql);
 return $result;
 }
 
 function script_make_command($scriptid,$hostid){
-	$host_db = DBfetch(DBselect('SELECT dns,useip,ip FROM hosts WHERE hostid='.$hostid));
-	$script_db = DBfetch(DBselect('SELECT command FROM scripts WHERE scriptid='.$scriptid));
+	$host_db = DBfetch(DBselect('SELECT dns,useip,ip FROM hosts WHERE hostid='.zbx_dbstr($hostid)));
+	$script_db = DBfetch(DBselect('SELECT command FROM scripts WHERE scriptid='.zbx_dbstr($scriptid)));
 
 	if($host_db && $script_db){
 		$command = $script_db['command'];
Index: frontends/php/include/reports.inc.php
===================================================================
--- frontends/php/include/reports.inc.php	(revision 38884)
+++ frontends/php/include/reports.inc.php	(working copy)
@@ -58,10 +58,10 @@
 		$cmbHGrps->addItem(0,S_ALL_SMALL);
 
 		$sql_cond = ' AND h.hostid=ht.hostid ';
-		if($_REQUEST['hostid'] > 0)	$sql_cond.=' AND ht.templateid='.$_REQUEST['hostid'];
+		if($_REQUEST['hostid'] > 0)	$sql_cond.=' AND ht.templateid='.zbx_dbstr($_REQUEST['hostid']);
 
 		if(isset($_REQUEST['tpl_triggerid']) && ($_REQUEST['tpl_triggerid'] > 0))
-			$sql_cond.= ' AND t.templateid='.$_REQUEST['tpl_triggerid'];
+			$sql_cond.= ' AND t.templateid='.zbx_dbstr($_REQUEST['tpl_triggerid']);
 
 		$result = DBselect('SELECT DISTINCT g.groupid,g.name '.
 			' FROM triggers t,hosts h,items i,functions f, hosts_templates ht, groups g, hosts_groups hg '.
@@ -85,7 +85,7 @@
 				);
 		}
 
-		$sql_cond=($_REQUEST['hostid'] > 0)?' AND h.hostid='.$_REQUEST['hostid']:' AND '.DBcondition('h.hostid',$available_hosts);
+		$sql_cond=($_REQUEST['hostid'] > 0)?' AND h.hostid='.zbx_dbstr($_REQUEST['hostid']):' AND '.DBcondition('h.hostid',$available_hosts);
 		$sql = 'SELECT DISTINCT t.triggerid,t.description '.
 			' FROM triggers t,hosts h,items i,functions f '.
 			' WHERE f.itemid=i.itemid '.
Index: frontends/php/include/classes/class.cchart.php
===================================================================
--- frontends/php/include/classes/class.cchart.php	(revision 38884)
+++ frontends/php/include/classes/class.cchart.php	(working copy)
@@ -250,9 +250,9 @@
 						' count(*) as count,avg(value) as avg,min(value) as min,'.
 						' max(value) as max,max(clock) as clock'.
 					' FROM history '.
-					' WHERE itemid='.$this->items[$i]['itemid'].
-						' AND clock>='.$from_time.
-						' AND clock<='.$to_time.
+					' WHERE itemid='.zbx_dbstr($this->items[$i]['itemid']).
+						' AND clock>='.zbx_dbstr($from_time).
+						' AND clock<='.zbx_dbstr($to_time).
 					' GROUP BY itemid,'.$calc_field
 					,
 
@@ -260,9 +260,9 @@
 						' count(*) as count,avg(value) as avg,min(value) as min,'.
 						' max(value) as max,max(clock) as clock'.
 					' FROM history_uint '.
-					' WHERE itemid='.$this->items[$i]['itemid'].
-						' AND clock>='.$from_time.
-						' AND clock<='.$to_time.
+					' WHERE itemid='.zbx_dbstr($this->items[$i]['itemid']).
+						' AND clock>='.zbx_dbstr($from_time).
+						' AND clock<='.zbx_dbstr($to_time).
 					' GROUP BY itemid,'.$calc_field
 					);
 			}
@@ -273,9 +273,9 @@
 						' sum(num) as count,avg(value_avg) as avg,min(value_min) as min,'.
 						' max(value_max) as max,max(clock) as clock'.
 					' FROM trends '.
-					' WHERE itemid='.$this->items[$i]['itemid'].
-						' AND clock>='.$from_time.
-						' AND clock<='.$to_time.
+					' WHERE itemid='.zbx_dbstr($this->items[$i]['itemid']).
+						' AND clock>='.zbx_dbstr($from_time).
+						' AND clock<='.zbx_dbstr($to_time).
 					' GROUP BY itemid,'.$calc_field
 					,
 
@@ -283,9 +283,9 @@
 						' sum(num) as count,avg(value_avg) as avg,min(value_min) as min,'.
 						' max(value_max) as max,max(clock) as clock'.
 					' FROM trends_uint '.
-					' WHERE itemid='.$this->items[$i]['itemid'].
-						' AND clock>='.$from_time.
-						' AND clock<='.$to_time.
+					' WHERE itemid='.zbx_dbstr($this->items[$i]['itemid']).
+						' AND clock>='.zbx_dbstr($from_time).
+						' AND clock<='.zbx_dbstr($to_time).
 					' GROUP BY itemid,'.$calc_field
 					);
 
@@ -451,7 +451,7 @@
 						' AND tr.status='.TRIGGER_STATUS_ENABLED.
 						' AND i.itemid=f.itemid '.
 						' AND h.hostid=i.hostid '.
-						' AND f.itemid='.$item['itemid'].
+						' AND f.itemid='.zbx_dbstr($item['itemid']).
 					' ORDER BY tr.priority';
 			$db_triggers = DBselect($sql);
 			while(($trigger = DBfetch($db_triggers)) && ($cnt < $max)){
Index: frontends/php/include/classes/class.cpie.php
===================================================================
--- frontends/php/include/classes/class.cpie.php	(revision 38884)
+++ frontends/php/include/classes/class.cpie.php	(working copy)
@@ -179,9 +179,9 @@
 						' max(h.value) AS max,max(h.clock) AS clock, max(i.lastvalue) as lst '.
 					' FROM history h '.
 						' LEFT JOIN items i ON h.itemid = i.itemid'.
-					' WHERE h.itemid='.$this->items[$i]['itemid'].
-						' AND h.clock>='.$from_time.
-						' AND h.clock<='.$to_time.
+					' WHERE h.itemid='.zbx_dbstr($this->items[$i]['itemid']).
+						' AND h.clock>='.zbx_dbstr($from_time).
+						' AND h.clock<='.zbx_dbstr($to_time).
 					' GROUP BY h.itemid'
 					,
 
@@ -190,9 +190,9 @@
 						' max(hu.value) AS max,max(hu.clock) AS clock, max(i.lastvalue) as lst'.
 					' FROM history_uint hu '.
 						' LEFT JOIN items i ON hu.itemid = i.itemid'.
-					' WHERE hu.itemid='.$this->items[$i]['itemid'].
-						' AND hu.clock>='.$from_time.
-						' AND hu.clock<='.$to_time.
+					' WHERE hu.itemid='.zbx_dbstr($this->items[$i]['itemid']).
+						' AND hu.clock>='.zbx_dbstr($from_time).
+						' AND hu.clock<='.zbx_dbstr($to_time).
 					' GROUP BY hu.itemid'
 					);
 			}
@@ -204,9 +204,9 @@
 						' max(t.value_max) AS max,max(t.clock) AS clock, max(i.lastvalue) as lst'.
 					' FROM trends t '.
 						' LEFT JOIN items i ON t.itemid = i.itemid'.
-					' WHERE t.itemid='.$this->items[$i]['itemid'].
-						' AND t.clock>='.$from_time.
-						' AND t.clock<='.$to_time.
+					' WHERE t.itemid='.zbx_dbstr($this->items[$i]['itemid']).
+						' AND t.clock>='.zbx_dbstr($from_time).
+						' AND t.clock<='.zbx_dbstr($to_time).
 					' GROUP BY t.itemid'
 					,
 
@@ -215,9 +215,9 @@
 						' max(t.value_max) AS max,max(t.clock) AS clock, max(i.lastvalue) as lst'.
 					' FROM trends_uint t '.
 						' LEFT JOIN items i ON t.itemid = i.itemid'.
-					' WHERE t.itemid='.$this->items[$i]['itemid'].
-						' AND t.clock>='.$from_time.
-						' AND t.clock<='.$to_time.
+					' WHERE t.itemid='.zbx_dbstr($this->items[$i]['itemid']).
+						' AND t.clock>='.zbx_dbstr($from_time).
+						' AND t.clock<='.zbx_dbstr($to_time).
 					' GROUP BY t.itemid'
 					);
 			}
Index: frontends/php/include/maps.inc.php
===================================================================
--- frontends/php/include/maps.inc.php	(revision 38884)
+++ frontends/php/include/maps.inc.php	(working copy)
@@ -60,7 +60,7 @@
 	}
 
 	function get_sysmap_by_sysmapid($sysmapid){
-		$row = DBfetch(DBselect('SELECT * FROM sysmaps WHERE sysmapid='.$sysmapid));
+		$row = DBfetch(DBselect('SELECT * FROM sysmaps WHERE sysmapid='.zbx_dbstr($sysmapid)));
 		if($row){
 			return	$row;
 		}
@@ -99,9 +99,9 @@
 
 		$result&=DBexecute('INSERT INTO sysmaps_links '.
 			' (linkid,sysmapid,label,selementid1,selementid2,drawtype,color) '.
-			' VALUES ('.$linkid.','.$link['sysmapid'].','.zbx_dbstr($link['label']).','.
-						$link['selementid1'].','.$link['selementid2'].','.
-						$link['drawtype'].','.zbx_dbstr($link['color']).')');
+			' VALUES ('.$linkid.','.zbx_dbstr($link['sysmapid']).','.zbx_dbstr($link['label']).','.
+						zbx_dbstr($link['selementid1']).','.zbx_dbstr($link['selementid2']).','.
+						zbx_dbstr($link['drawtype']).','.zbx_dbstr($link['color']).')');
 
 		if(!$result)
 			return $result;
@@ -138,13 +138,13 @@
 		}
 
 		$result&=DBexecute('UPDATE sysmaps_links SET '.
-							' sysmapid='.$link['sysmapid'].', '.
+							' sysmapid='.zbx_dbstr($link['sysmapid']).', '.
 							' label='.zbx_dbstr($link['label']).', '.
-							' selementid1='.$link['selementid1'].', '.
-							' selementid2='.$link['selementid2'].', '.
-							' drawtype='.$link['drawtype'].', '.
+							' selementid1='.zbx_dbstr($link['selementid1']).', '.
+							' selementid2='.zbx_dbstr($link['selementid2']).', '.
+							' drawtype='.zbx_dbstr($link['drawtype']).', '.
 							' color='.zbx_dbstr($link['color']).
-						' WHERE linkid='.$link['linkid']);
+						' WHERE linkid='.zbx_dbstr($link['linkid']));
 	return	$result;
 	}
 
@@ -160,7 +160,7 @@
 	function add_link_trigger($linkid,$triggerid,$drawtype,$color){
 		$linktriggerid=get_dbid("sysmaps_link_triggers","linktriggerid");
 		$sql = 'INSERT INTO sysmaps_link_triggers (linktriggerid,linkid,triggerid,drawtype,color) '.
-					" VALUES ($linktriggerid,$linkid,$triggerid,$drawtype,".zbx_dbstr($color).')';
+					' VALUES ('.zbx_dbstr($linktriggerid).','.zbx_dbstr($linkid).','.zbx_dbstr($triggerid).','.zbx_dbstr($drawtype).','.zbx_dbstr($color).')';
 	return DBexecute($sql);
 	}
 
@@ -188,7 +188,7 @@
 
 		$db_elements = DBselect('SELECT elementid, elementtype '.
 						' FROM sysmaps_elements '.
-						' WHERE sysmapid='.$elementid);
+						' WHERE sysmapid='.zbx_dbstr($elementid));
 
 		while($element = DBfetch($db_elements)){
 			if(check_circle_elements_link($sysmapid,$element["elementid"],$element["elementtype"]))
@@ -564,14 +564,14 @@
 			$resolveHostMacros = true;
 
 			if($selement['elementtype'] == SYSMAP_ELEMENT_TYPE_HOST){
-				$sql = 'SELECT host, dns, ip, useip FROM hosts WHERE hostid='.$selement['elementid'];
+				$sql = 'SELECT host, dns, ip, useip FROM hosts WHERE hostid='.zbx_dbstr($selement['elementid']);
 			}
 			else{
 				$sql ='SELECT h.host, h.dns, h.ip, h.useip'.
 					' FROM hosts h, items i, functions f'.
 					' WHERE h.hostid=i.hostid'.
 					' AND i.itemid=f.itemid'.
-					' AND f.triggerid='.$selement['elementid'];
+					' AND f.triggerid='.zbx_dbstr($selement['elementid']);
 			}
 			$db_host = DBfetch(DBselect($sql));
 		}
@@ -716,7 +716,7 @@
 				$sql = 'SELECT '.$function.'(value) as value '.
 						' FROM '.$history_table.
 						' WHERE clock>'.(time() - $parameter).
-						' AND itemid='.$item['itemid'];
+						' AND itemid='.zbx_dbstr($item['itemid']);
 				$result = DBselect($sql);
 				if(null === ($row = DBfetch($result)) || null === $row['value'])
 					$label = str_replace($expr, '('.S_NO_DATA_SMALL.')', $label);
@@ -742,7 +742,7 @@
 			case SYSMAP_ELEMENT_TYPE_MAP:
 				$sql = 'SELECT DISTINCT elementtype,elementid'.
 						' FROM sysmaps_elements'.
-						' WHERE sysmapid='.$db_element['elementid'];
+						' WHERE sysmapid='.zbx_dbstr($db_element['elementid']);
 				$db_mapselements = DBselect($sql);
 				while($db_mapelement = DBfetch($db_mapselements)){
 					get_map_elements($db_mapelement, $elements);
Index: frontends/php/include/hosts.inc.php
===================================================================
--- frontends/php/include/hosts.inc.php	(revision 38884)
+++ frontends/php/include/hosts.inc.php	(working copy)
@@ -22,7 +22,7 @@
 	function setHostGroupInternal($groupids, $internal=ZBX_NOT_INTERNAL_GROUP){
 		zbx_value2array($groupids);
 
-		$sql = 'UPDATE groups SET internal='.$internal.' WHERE '.DBcondition('groupid', $groupids);
+		$sql = 'UPDATE groups SET internal='.zbx_dbstr($internal).' WHERE '.DBcondition('groupid', $groupids);
 		$result = DBexecute($sql);
 	return $result;
 	}
@@ -67,7 +67,7 @@
 		zbx_value2array($templateids);
 
 		$result = delete_template_elements($hostid, $templateids, $unlink_mode);
-		$result&= DBexecute('DELETE FROM hosts_templates WHERE hostid='.$hostid.' AND '.DBcondition('templateid',$templateids));
+		$result&= DBexecute('DELETE FROM hosts_templates WHERE hostid='.zbx_dbstr($hostid).' AND '.DBcondition('templateid',$templateids));
 	return $result;
 	}
 
@@ -274,7 +274,7 @@
 // delete host
 		foreach($hostids as $id){	/* The section should be improved */
 			$host_old = get_host_by_hostid($id);
-			$result = DBexecute('DELETE FROM hosts WHERE hostid='.$id);
+			$result = DBexecute('DELETE FROM hosts WHERE hostid='.zbx_dbstr($id));
 			if($result){
 				if($host_old['status'] == HOST_STATUS_TEMPLATE){
 					info(S_TEMPLATE.SPACE.$host_old['host'].SPACE.S_HOST_HAS_BEEN_DELETED_MSG_PART2);
@@ -389,7 +389,7 @@
 
 		foreach ($groupids as $id) {	/* The section should be improved */
 			$hostgroup_old = get_hostgroup_by_groupid($id);
-			$result = DBexecute('DELETE FROM groups WHERE groupid='.$id);
+			$result = DBexecute('DELETE FROM groups WHERE groupid='.zbx_dbstr($id));
 			if ($result)
 				add_audit_ext(AUDIT_ACTION_DELETE, AUDIT_RESOURCE_HOST_GROUP, $id, $hostgroup_old['name'], 'groups', NULL, NULL);
 			else
@@ -400,7 +400,7 @@
 	}
 
 	function get_hostgroup_by_groupid($groupid){
-		$result=DBselect("select * from groups where groupid=".$groupid);
+		$result=DBselect("select * from groups where groupid=".zbx_dbstr($groupid));
 		$row=DBfetch($result);
 		if($row){
 			return $row;
@@ -421,7 +421,7 @@
 		else
 			$result = DBselect('SELECT * FROM hosts WHERE status IN ('.HOST_STATUS_PROXY_ACTIVE.','.HOST_STATUS_PROXY_PASSIVE.')'.
 					' and '.DBin_node('hostid').' AND host='.zbx_dbstr($name).
-					' and hostid<>'.$proxyid);
+					' and hostid<>'.zbx_dbstr($proxyid));
 
 		if(DBfetch($result)){
 			error(S_PROXY.SPACE."'$name'".SPACE.S_ALREADY_EXISTS_SMALL);
@@ -431,7 +431,7 @@
 		if(is_null($proxyid)){
 			$proxyid=get_dbid('hosts','hostid');
 			if(!DBexecute('INSERT INTO hosts (hostid,host,status,useip,dns,ip,port)'.
-				' values ('.$proxyid.','.zbx_dbstr($name).','.$status.','.$useip.','.zbx_dbstr($dns).','.zbx_dbstr($ip).','.$port.')'))
+				' values ('.$proxyid.','.zbx_dbstr($name).','.zbx_dbstr($status).','.zbx_dbstr($useip).','.zbx_dbstr($dns).','.zbx_dbstr($ip).','.zbx_dbstr($port).')'))
 			{
 				return false;
 			}
@@ -439,7 +439,7 @@
 			return $proxyid;
 		}
 		else
-			return DBexecute('update hosts set host='.zbx_dbstr($name).',status='.$status.',useip='.$useip.',dns='.zbx_dbstr($dns).',ip='.zbx_dbstr($ip).',port='.$port.' where hostid='.$proxyid);
+			return DBexecute('update hosts set host='.zbx_dbstr($name).',status='.zbx_dbstr($status).',useip='.zbx_dbstr($useip).',dns='.zbx_dbstr($dns).',ip='.zbx_dbstr($ip).',port='.zbx_dbstr($port).' where hostid='.zbx_dbstr($proxyid));
 	}
 
 	function delete_proxy($proxyids){
@@ -474,10 +474,10 @@
 	}
 
 	function update_hosts_by_proxyid($proxyid,$hosts=array()){
-		DBexecute('update hosts set proxy_hostid=0 where proxy_hostid='.$proxyid);
+		DBexecute('update hosts set proxy_hostid=0 where proxy_hostid='.zbx_dbstr($proxyid));
 
 		foreach($hosts as $hostid){
-			DBexecute('update hosts set proxy_hostid='.$proxyid.' where hostid='.$hostid);
+			DBexecute('update hosts set proxy_hostid='.zbx_dbstr($proxyid).' where hostid='.zbx_dbstr($hostid));
 		}
 	}
 
@@ -532,7 +532,7 @@
 	}
 
 	function get_host_by_hostid($hostid,$no_error_message=0){
-		$sql='SELECT * FROM hosts WHERE hostid='.$hostid;
+		$sql='SELECT * FROM hosts WHERE hostid='.zbx_dbstr($hostid);
 		$result=DBselect($sql);
 		$row=DBfetch($result);
 		if($row){
@@ -570,7 +570,7 @@
 			if($status != $host['status']){
 //				$hosts[$host['hostid']] = $host['hostid'];
 				update_trigger_value_to_unknown_by_hostid($host['hostid']);
-				$res = DBexecute('UPDATE hosts SET status='.$status.' WHERE hostid='.$host['hostid']);
+				$res = DBexecute('UPDATE hosts SET status='.zbx_dbstr($status).' WHERE hostid='.zbx_dbstr($host['hostid']));
 				if($res){
 					$host_new = $host;//get_host_by_hostid($host['hostid']);
 					$host_new['status'] = $status;
@@ -613,7 +613,7 @@
 		$db_templates = DBselect('SELECT DISTINCT h.hostid,h.host '.
 				' FROM hosts_templates ht '.
 					' LEFT JOIN hosts h ON h.hostid=ht.templateid '.
-				' WHERE ht.hostid='.$hostid.
+				' WHERE ht.hostid='.zbx_dbstr($hostid).
 				' ORDER BY h.host');
 
 		while($template_data = DBfetch($db_templates)){
@@ -1153,7 +1153,7 @@
 
 		if($_REQUEST['groupid'] > 0){
 			if($_REQUEST['hostid'] > 0){
-				$sql = 'SELECT groupid FROM hosts_groups WHERE hostid='.$_REQUEST['hostid'].' AND groupid='.$_REQUEST['groupid'];
+				$sql = 'SELECT groupid FROM hosts_groups WHERE hostid='.zbx_dbstr($_REQUEST['hostid']).' AND groupid='.zbx_dbstr($_REQUEST['groupid']);
 				if(!DBfetch(DBselect($sql))){
 					$_REQUEST['hostid'] = 0;
 				}
@@ -1265,9 +1265,9 @@
 		$sql = 'SELECT applicationid, templateid
 			FROM applications
 			WHERE name='.zbx_dbstr($name).'
-				AND hostid='.$hostid;
+				AND hostid='.zbx_dbstr($hostid);
 		if(!is_null($applicationid)){
-			$sql .= ' AND applicationid<>'.$applicationid;
+			$sql .= ' AND applicationid<>'.zbx_dbstr($applicationid);
 		}
 		$db_app = DBfetch(DBselect($sql));
 		if($db_app && (($templateid == 0) || ($templateid && $db_app['templateid'] && $templateid != $db_app['templateid']))){
@@ -1290,15 +1290,15 @@
 			$applicationid_new = get_dbid('applications', 'applicationid');
 
 			$sql = 'INSERT INTO applications (applicationid, name, hostid, templateid) '.
-				" VALUES ($applicationid_new, ".zbx_dbstr($name).", $hostid, $templateid)";
+				' VALUES ('.zbx_dbstr($applicationid_new).','.zbx_dbstr($name).','.zbx_dbstr($hostid).','.zbx_dbstr($templateid).')';
 			if($result = DBexecute($sql)){
 				info(S_ADDED_NEW_APPLICATION.SPACE.'"'.$host['host'].':'.$name.'"');
 			}
 		}
 		else{
 			$old_app = get_application_by_applicationid($applicationid);
-			$result = DBexecute('UPDATE applications SET name='.zbx_dbstr($name).', hostid='.$hostid.', templateid='.$templateid.
-				' WHERE applicationid='.$applicationid);
+			$result = DBexecute('UPDATE applications SET name='.zbx_dbstr($name).', hostid='.zbx_dbstr($hostid).', templateid='.zbx_dbstr($templateid).
+				' WHERE applicationid='.zbx_dbstr($applicationid));
 			if($result)
 				info(S_APPLICATION.SPACE.'"'.$host['host'].':'.$old_app['name'].'"'.SPACE.S_UPDATED_SMALL);
 		}
@@ -1437,7 +1437,7 @@
 	}
 
 	function get_application_by_applicationid($applicationid,$no_error_message=0){
-		$result = DBselect("select * from applications where applicationid=".$applicationid);
+		$result = DBselect('select * from applications where applicationid='.zbx_dbstr($applicationid));
 		$row=DBfetch($result);
 		if($row)
 		{
@@ -1450,7 +1450,7 @@
 	}
 
 	function get_applications_by_templateid($applicationid){
-		return DBselect("select * from applications where templateid=".$applicationid);
+		return DBselect('select * from applications where templateid='.zbx_dbstr($applicationid));
 	}
 
 	function get_realhost_by_applicationid($applicationid){
@@ -1462,7 +1462,7 @@
 	}
 
 	function get_host_by_applicationid($applicationid){
-		$sql="select h.* from hosts h, applications a where a.hostid=h.hostid and a.applicationid=$applicationid";
+		$sql='select h.* from hosts h, applications a where a.hostid=h.hostid and a.applicationid='.zbx_dbstr($applicationid);
 		$result=DBselect($sql);
 		$row=DBfetch($result);
 		if($row)
@@ -1474,7 +1474,7 @@
 	}
 
 	function get_applications_by_hostid($hostid){
-		return DBselect('select * from applications where hostid='.$hostid);
+		return DBselect('select * from applications where hostid='.zbx_dbstr($hostid));
 	}
 
 	/*
@@ -1513,7 +1513,7 @@
 			}
 
 			if ($unlink_mode) {
-				if (DBexecute("update applications set templateid=0 where applicationid=".$db_app["applicationid"])) {
+				if (DBexecute("update applications set templateid=0 where applicationid=".zbx_dbstr($db_app["applicationid"]))) {
 					info(S_APPLICATION.SPACE.'"'.$host["host"].':'.$db_app["name"].'"'.SPACE.S_UNLINKED_SMALL);
 				}
 			}
@@ -1612,7 +1612,7 @@
 
 	function add_host_profile($hostid,$devicetype,$name,$os,$serialno,$tag,$macaddress,$hardware,$software,$contact,$location,$notes){
 
-		$result=DBselect('SELECT * FROM hosts_profiles WHERE hostid='.$hostid);
+		$result=DBselect('SELECT * FROM hosts_profiles WHERE hostid='.zbx_dbstr($hostid));
 		if(DBfetch($result)){
 			error(S_HOST_PROFILE.SPACE.S_ALREADY_EXISTS);
 			return 0;
@@ -1653,7 +1653,7 @@
 			'poc_1_name','poc_1_email','poc_1_phone_1','poc_1_phone_2','poc_1_cell','poc_1_screen','poc_1_notes','poc_2_name',
 			'poc_2_email','poc_2_phone_1','poc_2_phone_2','poc_2_cell','poc_2_screen','poc_2_notes');
 
-		$result=DBselect('SELECT * FROM hosts_profiles_ext WHERE hostid='.$hostid);
+		$result=DBselect('SELECT * FROM hosts_profiles_ext WHERE hostid='.zbx_dbstr($hostid));
 		if(DBfetch($result)){
 			error(S_HOST_PROFILE.SPACE.S_ALREADY_EXISTS);
 			return false;
Index: frontends/php/include/users.inc.php
===================================================================
--- frontends/php/include/users.inc.php	(revision 38884)
+++ frontends/php/include/users.inc.php	(working copy)
@@ -91,11 +91,11 @@
 	function add_user_to_group($userid,$usrgrpid){
 		$result = false;
 		if(granted2move_user($userid,$usrgrpid)){
-			DBexecute('DELETE FROM users_groups WHERE userid='.$userid.' AND usrgrpid='.$usrgrpid);
+			DBexecute('DELETE FROM users_groups WHERE userid='.zbx_dbstr($userid).' AND usrgrpid='.zbx_dbstr($usrgrpid));
 
 			$users_groups_id = get_dbid("users_groups","id");
 			$result = DBexecute('INSERT INTO users_groups (id,usrgrpid,userid) '.
-									' VALUES ('.$users_groups_id.','.$usrgrpid.','.$userid.')');
+									' VALUES ('.$users_groups_id.','.zbx_dbstr($usrgrpid).','.zbx_dbstr($userid).')');
 		}
 		else{
 			error(S_USER_CANNOT_CHANGE_STATUS);
@@ -106,7 +106,7 @@
 	function remove_user_from_group($userid,$usrgrpid){
 		$result = false;
 		if(granted2move_user($userid,$usrgrpid)){
-			$result = DBexecute('DELETE FROM users_groups WHERE userid='.$userid.' AND usrgrpid='.$usrgrpid);
+			$result = DBexecute('DELETE FROM users_groups WHERE userid='.zbx_dbstr($userid).' AND usrgrpid='.zbx_dbstr($usrgrpid));
 		}
 		else{
 			error(S_USER_CANNOT_CHANGE_STATUS);
@@ -156,7 +156,7 @@
 		if($users_status == GROUP_STATUS_DISABLED) $grant = granted2update_group($usrgrpids);
 
 		if($grant)
-			$res = DBexecute('UPDATE usrgrp SET users_status='.$users_status.' WHERE '.DBcondition('usrgrpid',$usrgrpids));
+			$res = DBexecute('UPDATE usrgrp SET users_status='.zbx_dbstr($users_status).' WHERE '.DBcondition('usrgrpid',$usrgrpids));
 		else
 			error(S_USER_CANNOT_CHANGE_STATUS);
 
@@ -172,7 +172,7 @@
 		if($gui_access == GROUP_GUI_ACCESS_DISABLED) $grant = granted2update_group($usrgrpids);
 
 		if($grant)
-			$res = DBexecute('UPDATE usrgrp SET gui_access='.$gui_access.' WHERE '.DBcondition('usrgrpid',$usrgrpids));
+			$res = DBexecute('UPDATE usrgrp SET gui_access='.zbx_dbstr($gui_access).' WHERE '.DBcondition('usrgrpid',$usrgrpids));
 		else
 			error(S_USER_CANNOT_CHANGE_GUI_ACCESS);
 
@@ -182,14 +182,14 @@
 	function change_group_api_access($usrgrpids, $api_access){
 		zbx_value2array($usrgrpids);
 		$res = false;
-		$res = DBexecute('UPDATE usrgrp SET api_access='.$api_access.' WHERE '.DBcondition('usrgrpid',$usrgrpids));
+		$res = DBexecute('UPDATE usrgrp SET api_access='.zbx_dbstr($api_access).' WHERE '.DBcondition('usrgrpid',$usrgrpids));
 	return $res;
 	}
 
 	function change_group_debug_mode($usrgrpids, $debug_mode){
 		zbx_value2array($usrgrpids);
 		$res = false;
-		$res = DBexecute('UPDATE usrgrp SET debug_mode='.$debug_mode.' WHERE '.DBcondition('usrgrpid',$usrgrpids));
+		$res = DBexecute('UPDATE usrgrp SET debug_mode='.zbx_dbstr($debug_mode).' WHERE '.DBcondition('usrgrpid',$usrgrpids));
 	return $res;
 	}
 ?>
Index: frontends/php/include/events.inc.php
===================================================================
--- frontends/php/include/events.inc.php	(revision 38884)
+++ frontends/php/include/events.inc.php	(working copy)
@@ -30,7 +30,7 @@
 	function get_tr_event_by_eventid($eventid){
 		$sql = 'SELECT e.*,t.triggerid, t.description,t.priority,t.status,t.type,t.expression '.
 				' FROM events e,triggers t '.
-				' WHERE e.eventid='.$eventid.
+				' WHERE e.eventid='.zbx_dbstr($eventid).
 					' AND e.object='.EVENT_OBJECT_TRIGGER.
 					' AND t.triggerid=e.objectid';
 		$result = DBfetch(DBselect($sql));
@@ -116,7 +116,7 @@
 	if(empty($events)){
 		$sql = 'SELECT e.eventid '.
 				' FROM events e '.
-				' WHERE e.objectid='.$row['triggerid'].$sql_cond.
+				' WHERE e.objectid='.zbx_dbstr($row['triggerid']).$sql_cond.
 					' AND e.object='.EVENT_OBJECT_TRIGGER.
 				' ORDER BY e.object, e.objectid, e.eventid';
 		$res = DBselect($sql,1);
@@ -127,8 +127,8 @@
 		$eventid = $events[0]['eventid'];
 		$sql = 'SELECT e.eventid '.
 				' FROM events e '.
-				' WHERE e.eventid > '.$eventid.
-					' AND e.objectid='.$row['triggerid'].$sql_cond.
+				' WHERE e.eventid > '.zbx_dbstr($eventid).
+					' AND e.objectid='.zbx_dbstr($row['triggerid']).$sql_cond.
 					' AND e.object='.EVENT_OBJECT_TRIGGER.
 				' ORDER BY e.object, e.objectid, e.eventid';
 		$res = DBselect($sql,1);
@@ -147,10 +147,10 @@
 
 		$sql = 'SELECT e.eventid,e.clock '.
 				' FROM events e '.
-				' WHERE e.eventid > '.$eventid.
-					' AND e.objectid='.$row['triggerid'].
+				' WHERE e.eventid > '.zbx_dbstr($eventid).
+					' AND e.objectid='.zbx_dbstr($row['triggerid']).
 					' AND e.object='.EVENT_OBJECT_TRIGGER.
-					' AND e.value='.$row['value'].
+					' AND e.value='.zbx_dbstr($row['value']).
 				' ORDER BY e.object, e.objectid, e.eventid';
 		$res = DBselect($sql,1);
 		$rows = DBfetch($res);
@@ -179,8 +179,8 @@
 
 	$sql = 'SELECT e.eventid, e.clock, e.value '.
 			' FROM events e '.
-			' WHERE e.objectid='.$row['triggerid'].
-				' AND e.eventid < '.$row['eventid'].
+			' WHERE e.objectid='.zbx_dbstr($row['triggerid']).
+				' AND e.eventid < '.zbx_dbstr($row['eventid']).
 				' AND e.object='.EVENT_OBJECT_TRIGGER.
 				' AND e.value='.TRIGGER_VALUE_FALSE.
 			' ORDER BY e.object DESC, e.objectid DESC, e.eventid DESC';
@@ -188,8 +188,8 @@
 
 	$sql = 'SELECT e.eventid, e.clock, e.value '.
 			' FROM events e'.
-			' WHERE e.objectid='.$row['triggerid'].
-				' AND e.eventid < '.$row['eventid'].
+			' WHERE e.objectid='.zbx_dbstr($row['triggerid']).
+				' AND e.eventid < '.zbx_dbstr($row['eventid']).
 				' AND e.object='.EVENT_OBJECT_TRIGGER.
 				' AND e.value='.TRIGGER_VALUE_TRUE.
 			' ORDER BY e.object DESC, e.objectid DESC, e.eventid DESC';
@@ -199,8 +199,8 @@
 	if($hide_unknown == 0){
 		$sql = 'SELECT e.eventid, e.clock, e.value '.
 				' FROM events e'.
-				' WHERE e.objectid='.$row['triggerid'].
-					' AND e.eventid < '.$row['eventid'].
+				' WHERE e.objectid='.zbx_dbstr($row['triggerid']).
+					' AND e.eventid < '.zbx_dbstr($row['eventid']).
 					' AND e.object='.EVENT_OBJECT_TRIGGER.
 					' AND e.value='.TRIGGER_VALUE_UNKNOWN.
 				' ORDER BY e.object DESC, e.objectid DESC, e.eventid DESC';
@@ -239,8 +239,8 @@
 
 	$sql = 'SELECT e.eventid, e.value, e.clock '.
 		' FROM events e'.
-		' WHERE e.objectid='.$event['objectid'].
-			' AND e.eventid>'.$event['eventid'].
+		' WHERE e.objectid='.zbx_dbstr($event['objectid']).
+			' AND e.eventid>'.zbx_dbstr($event['eventid']).
 			' AND e.object='.EVENT_OBJECT_TRIGGER.
 		' ORDER BY e.object, e.objectid, e.eventid';
 
@@ -405,9 +405,9 @@
 	$event_list = array();
 	$sql = 'SELECT * '.
 			' FROM events '.
-			' WHERE eventid<='.$eventid.
+			' WHERE eventid<='.zbx_dbstr($eventid).
 				' AND object='.EVENT_OBJECT_TRIGGER.
-				' AND objectid='.$triggerid.
+				' AND objectid='.zbx_dbstr($triggerid).
 			' ORDER BY eventid DESC';
 	$db_events = DBselect($sql, ZBX_WIDGET_ROWS);
 
Index: frontends/php/include/images.inc.php
===================================================================
--- frontends/php/include/images.inc.php	(revision 38884)
+++ frontends/php/include/images.inc.php	(working copy)
@@ -29,7 +29,7 @@
 			$sql = 'SELECT i.imageid '.
 				' FROM images i '.
 				' WHERE '.DBin_node('i.imageid', false).
-					' AND imagetype='.$imagetype.
+					' AND imagetype='.zbx_dbstr($imagetype).
 				' ORDER BY name ASC';
 			$result = DBselect($sql,1);
 			if($image = DBfetch($result)) return $image;
@@ -44,7 +44,7 @@
 
 	function get_image_by_imageid($imageid){
 
-		$sql = 'SELECT * FROM images WHERE imageid='.$imageid;
+		$sql = 'SELECT * FROM images WHERE imageid='.zbx_dbstr($imageid);
 		$result = DBselect($sql);
 		if($row = DBfetch($result)){
 			$row['image'] = zbx_unescape_image($row['image']);
Index: frontends/php/include/maintenances.inc.php
===================================================================
--- frontends/php/include/maintenances.inc.php	(revision 38884)
+++ frontends/php/include/maintenances.inc.php	(working copy)
@@ -25,7 +25,7 @@
 	$sql = 'SELECT m.* '.
 			' FROM maintenances m '.
 			' WHERE '.DBin_node('m.maintenanceid').
-				' AND maintenanceid='.$maintenanceid;
+				' AND maintenanceid='.zbx_dbstr($maintenanceid);
 
 	$maintenance = DBfetch(DBselect($sql));
 return $maintenance;
Index: frontends/php/include/audit.inc.php
===================================================================
--- frontends/php/include/audit.inc.php	(revision 38884)
+++ frontends/php/include/audit.inc.php	(working copy)
@@ -81,7 +81,7 @@
 
 		if(($result = DBexecute('INSERT INTO auditlog (auditid,userid,clock,action,resourcetype,details,ip) '.
 			' VALUES ('.$auditid.','.$USER_DETAILS['userid'].','.time().','.
-						$action.','.$resourcetype.','.zbx_dbstr($details).','.
+						zbx_dbstr($action).','.zbx_dbstr($resourcetype).','.zbx_dbstr($details).','.
 						zbx_dbstr($ip).')')))
 		{
 			$result = $auditid;
@@ -120,7 +120,7 @@
 
 		$result = DBexecute('INSERT INTO auditlog (auditid,userid,clock,ip,action,resourcetype,resourceid,resourcename)'.
 				' values ('.$auditid.','.$USER_DETAILS['userid'].','.time().','.zbx_dbstr($ip).
-				','.$action.','.$resourcetype.','.$resourceid.','.zbx_dbstr($resourcename).')');
+				','.zbx_dbstr($action).','.zbx_dbstr($resourcetype).','.zbx_dbstr($resourceid).','.zbx_dbstr($resourcename).')');
 
 		if ($result && $action == AUDIT_ACTION_UPDATE) {
 			foreach ($values_diff as $id) {
Index: frontends/php/include/discovery.inc.php
===================================================================
--- frontends/php/include/discovery.inc.php	(revision 38884)
+++ frontends/php/include/discovery.inc.php	(working copy)
@@ -146,11 +146,11 @@
 	}
 
 	function get_discovery_rule_by_druleid($druleid){
-		return DBfetch(DBselect('select * from drules where druleid='.$druleid));
+		return DBfetch(DBselect('select * from drules where druleid='.zbx_dbstr($druleid)));
 	}
 
 	function set_discovery_rule_status($druleid, $status){
-		return DBexecute('update drules set status='.$status.' where druleid='.$druleid);
+		return DBexecute('update drules set status='.zbx_dbstr($status).' where druleid='.zbx_dbstr($druleid));
 	}
 
 	function add_discovery_check($druleid, $type, $ports, $key, $snmp_community,
@@ -168,9 +168,9 @@
 		$dcheckid = get_dbid('dchecks', 'dcheckid');
 		$result = DBexecute('insert into dchecks (dcheckid,druleid,type,ports,key_,snmp_community'.
 				',snmpv3_securityname,snmpv3_securitylevel,snmpv3_authpassphrase,snmpv3_privpassphrase) '.
-				' values ('.$dcheckid.','.$druleid.','.$type.','.zbx_dbstr($ports).','.
+				' values ('.$dcheckid.','.zbx_dbstr($druleid).','.zbx_dbstr($type).','.zbx_dbstr($ports).','.
 				zbx_dbstr($key).','.zbx_dbstr($snmp_community).','.zbx_dbstr($snmpv3_securityname).','.
-				$snmpv3_securitylevel.','.zbx_dbstr($snmpv3_authpassphrase).','.zbx_dbstr($snmpv3_privpassphrase).')');
+				zbx_dbstr($snmpv3_securitylevel).','.zbx_dbstr($snmpv3_authpassphrase).','.zbx_dbstr($snmpv3_privpassphrase).')');
 
 		if(!$result)
 			return $result;
@@ -192,7 +192,7 @@
 
 		$druleid = get_dbid('drules', 'druleid');
 		$result = DBexecute('insert into drules (druleid,proxy_hostid,name,iprange,delay,status) '.
-			' values ('.$druleid.','.$proxy_hostid.','.zbx_dbstr($name).','.zbx_dbstr($iprange).','.$delay.','.$status.')');
+			' values ('.$druleid.','.zbx_dbstr($proxy_hostid).','.zbx_dbstr($name).','.zbx_dbstr($iprange).','.zbx_dbstr($delay).','.zbx_dbstr($status).')');
 
 		if($result && isset($dchecks)){
 			$unique_dcheckid = 0;
@@ -204,8 +204,8 @@
 					$unique_dcheckid = $data['dcheckid'];
 			}
 			DBexecute('UPDATE drules'.
-					' SET unique_dcheckid='.$unique_dcheckid.
-					' WHERE druleid='.$druleid);
+					' SET unique_dcheckid='.zbx_dbstr($unique_dcheckid).
+					' WHERE druleid='.zbx_dbstr($druleid));
 
 			$result = $druleid;
 		}
@@ -229,8 +229,8 @@
 			}
 		}
 
-		$result = DBexecute('update drules set proxy_hostid='.$proxy_hostid.',name='.zbx_dbstr($name).',iprange='.zbx_dbstr($iprange).','.
-			'delay='.$delay.',status='.$status.' where druleid='.$druleid);
+		$result = DBexecute('update drules set proxy_hostid='.zbx_dbstr($proxy_hostid).',name='.zbx_dbstr($name).',iprange='.zbx_dbstr($iprange).','.
+			'delay='.zbx_dbstr($delay).',status='.zbx_dbstr($status).' where druleid='.zbx_dbstr($druleid));
 
 		if($result && isset($dchecks)){
 			$unique_dcheckid = 0;
@@ -245,8 +245,8 @@
 			}
 
 			DBexecute('UPDATE drules'.
-					' SET unique_dcheckid='.$unique_dcheckid.
-					' WHERE druleid='.$druleid);
+					' SET unique_dcheckid='.zbx_dbstr($unique_dcheckid).
+					' WHERE druleid='.zbx_dbstr($druleid));
 		}
 
 		if($result && isset($dchecks_deleted) && !empty($dchecks_deleted))
@@ -292,7 +292,7 @@
 		$sql = 'SELECT DISTINCT actionid '.
 				' FROM conditions '.
 				' WHERE conditiontype='.CONDITION_TYPE_DRULE.
-					" AND value='$druleid'";
+					' AND value='.zbx_dbstr($druleid);
 
 		$db_actions = DBselect($sql);
 		while($db_action = DBfetch($db_actions))
@@ -307,26 +307,26 @@
 // delete action conditions
 			DBexecute('DELETE FROM conditions '.
 					' WHERE conditiontype='.CONDITION_TYPE_DRULE.
-					" AND value='$druleid'");
+					' AND value='.zbx_dbstr($druleid));
 		}
 
 		if($result){
 			$db_dhosts = DBselect('select dhostid from dhosts'.
-					' where druleid='.$druleid.' and '.DBin_node('dhostid'));
+					' where druleid='.zbx_dbstr($druleid).' and '.DBin_node('dhostid'));
 
 			while ($result && ($db_dhost = DBfetch($db_dhosts)))
 				$result = DBexecute('delete from dservices where'.
-						' dhostid='.$db_dhost['dhostid']);
+						' dhostid='.zbx_dbstr($db_dhost['dhostid']));
 		}
 
 		if ($result)
-			$result = DBexecute('delete from dhosts where druleid='.$druleid);
+			$result = DBexecute('delete from dhosts where druleid='.zbx_dbstr($druleid));
 
 		if ($result)
-			$result = DBexecute('delete from dchecks where druleid='.$druleid);
+			$result = DBexecute('delete from dchecks where druleid='.zbx_dbstr($druleid));
 
 		if ($result)
-			$result = DBexecute('delete from drules where druleid='.$druleid);
+			$result = DBexecute('delete from drules where druleid='.zbx_dbstr($druleid));
 
 		return $result;
 	}
Index: frontends/php/include/nodes.inc.php
===================================================================
--- frontends/php/include/nodes.inc.php	(revision 38884)
+++ frontends/php/include/nodes.inc.php	(working copy)
@@ -30,7 +30,7 @@
 		foreach($nodeids as $nodeid){
 			$profileid = get_dbid('profiles', 'profileid');
 			$sql='INSERT INTO profiles (profileid, userid, idx, value_id, type)'.
-				' VALUES ('.$profileid.','.$USER_DETAILS['userid'].', '.zbx_dbstr('web.nodes.selected').','.$nodeid.', 4)';
+				' VALUES ('.$profileid.','.$USER_DETAILS['userid'].', '.zbx_dbstr('web.nodes.selected').','.zbx_dbstr($nodeid).', 4)';
 			DBexecute($sql);
 		}
 
@@ -287,19 +287,19 @@
 		}
 
 
-		if(DBfetch(DBselect('SELECT nodeid FROM nodes WHERE nodeid='.$new_nodeid))){
+		if(DBfetch(DBselect('SELECT nodeid FROM nodes WHERE nodeid='.zbx_dbstr($new_nodeid)))){
 			error(S_NODE_WITH_SAME_ID_ALREADY_EXISTS);
 			return false;
 		}
 
 		$nodetype = 0;
 		$sql = 'INSERT INTO nodes (nodeid,name,timezone,ip,port,slave_history,slave_trends, nodetype,masterid) '.
-			' VALUES ('.$new_nodeid.','.zbx_dbstr($name).','.$timezone.','.zbx_dbstr($ip).','.$port.','.$slave_history.','.
-			$slave_trends.','.$nodetype.','.$masterid.')';
+			' VALUES ('.zbx_dbstr($new_nodeid).','.zbx_dbstr($name).','.zbx_dbstr($timezone).','.zbx_dbstr($ip).','.zbx_dbstr($port).','.zbx_dbstr($slave_history).','.
+			zbx_dbstr($slave_trends).','.zbx_dbstr($nodetype).','.zbx_dbstr($masterid).')';
 		$result = DBexecute($sql);
 
 		if($result && $node_type == ZBX_NODE_MASTER){
-			DBexecute('UPDATE nodes SET masterid='.$new_nodeid.' WHERE nodeid='.$ZBX_LOCALNODEID);
+			DBexecute('UPDATE nodes SET masterid='.zbx_dbstr($new_nodeid).' WHERE nodeid='.$ZBX_LOCALNODEID);
 			$ZBX_CURMASTERID = $new_nodeid; /* apply Master node for this script */
 		}
 
@@ -313,16 +313,16 @@
 			return false;
 		}
 
-		$result = DBexecute('UPDATE nodes SET nodeid='.$new_nodeid.',name='.zbx_dbstr($name).','.
-			'timezone='.$timezone.',ip='.zbx_dbstr($ip).',port='.$port.','.
-			'slave_history='.$slave_history.',slave_trends='.$slave_trends.
-			' WHERE nodeid='.$nodeid);
+		$result = DBexecute('UPDATE nodes SET nodeid='.zbx_dbstr($new_nodeid).',name='.zbx_dbstr($name).','.
+			'timezone='.zbx_dbstr($timezone).',ip='.zbx_dbstr($ip).',port='.zbx_dbstr($port).','.
+			'slave_history='.zbx_dbstr($slave_history).',slave_trends='.zbx_dbstr($slave_trends).
+			' WHERE nodeid='.zbx_dbstr($nodeid));
 	return $result;
 	}
 
 	function delete_node($nodeid){
 		$result = false;
-		$node_data = DBfetch(DBselect('select * from nodes where nodeid='.$nodeid));
+		$node_data = DBfetch(DBselect('select * from nodes where nodeid='.zbx_dbstr($nodeid)));
 
 		$node_type = detect_node_type($node_data);
 
@@ -334,8 +334,8 @@
 			$result = (
 				// DBexecute("insert into housekeeper (housekeeperid,tablename,field,value)".
 					// " values ($housekeeperid,'nodes','nodeid',$nodeid)") &&
-				DBexecute('delete from nodes where nodeid='.$nodeid) &&
-				DBexecute('update nodes set masterid=0 where masterid='.$nodeid)
+				DBexecute('delete from nodes where nodeid='.zbx_dbstr($nodeid)) &&
+				DBexecute('update nodes set masterid=0 where masterid='.zbx_dbstr($nodeid))
 				);
 			error(S_DATABASE_STILL_CONTAINS_DATA_RELATED_DELETED_NODE);
 		}
@@ -345,7 +345,7 @@
 
 	function get_node_by_nodeid($nodeid)
 	{
-		return DBfetch(DBselect('select * from nodes where nodeid='.$nodeid));
+		return DBfetch(DBselect('select * from nodes where nodeid='.zbx_dbstr($nodeid)));
 	}
 
 	function get_node_path($nodeid, $result='/')
Index: frontends/php/include/valuemap.inc.php
===================================================================
--- frontends/php/include/valuemap.inc.php	(revision 38884)
+++ frontends/php/include/valuemap.inc.php	(working copy)
@@ -26,9 +26,9 @@
 		foreach($mappings as $map){
 			$mappingid = get_dbid("mappings","mappingid");
 
-			$result = DBexecute("insert into mappings (mappingid,valuemapid, value, newvalue)".
-				" values (".$mappingid.",".$valuemapid.",".zbx_dbstr($map["value"]).",".
-				zbx_dbstr($map["newvalue"]).")");
+			$result = DBexecute('insert into mappings (mappingid,valuemapid, value, newvalue)'.
+				' values ('.zbx_dbstr($mappingid).','.zbx_dbstr($valuemapid).','.zbx_dbstr($map["value"]).','.
+				zbx_dbstr($map["newvalue"]).')');
 
 			if(!$result)
 				return $result;
@@ -41,7 +41,7 @@
 
 		$valuemapid = get_dbid("valuemaps","valuemapid");
 
-		$result = DBexecute("insert into valuemaps (valuemapid,name) values ($valuemapid,".zbx_dbstr($name).")");
+		$result = DBexecute('insert into valuemaps (valuemapid,name) values ('.zbx_dbstr($valuemapid).','.zbx_dbstr($name).')');
 		if(!$result)
 			return $result;
 
@@ -59,7 +59,7 @@
 		if(!is_array($mappings))	return FALSE;
 
 		$result = DBexecute('UPDATE valuemaps SET name='.zbx_dbstr($name).
-			' WHERE valuemapid='.$valuemapid);
+			' WHERE valuemapid='.zbx_dbstr($valuemapid));
 
 		if(!$result)
 			return $result;
@@ -72,8 +72,8 @@
 	}
 
 	function delete_valuemap($valuemapid){
-		DBexecute('DELETE FROM mappings WHERE valuemapid='.$valuemapid);
-		DBexecute('DELETE FROM valuemaps WHERE valuemapid='.$valuemapid);
+		DBexecute('DELETE FROM mappings WHERE valuemapid='.zbx_dbstr($valuemapid));
+		DBexecute('DELETE FROM valuemaps WHERE valuemapid='.zbx_dbstr($valuemapid));
 	return TRUE;
 	}
 
@@ -85,7 +85,7 @@
 
 		$sql = 'SELECT newvalue '.
 				' FROM mappings '.
-				' WHERE valuemapid='.$valuemapid.
+				' WHERE valuemapid='.zbx_dbstr($valuemapid).
 					' AND value='.zbx_dbstr($value);
 		$result = DBselect($sql);
 		if($row = DBfetch($result)){
Index: frontends/php/api/classes/class.cgraph.php
===================================================================
--- frontends/php/api/classes/class.cgraph.php	(revision 38884)
+++ frontends/php/api/classes/class.cgraph.php	(working copy)
@@ -225,7 +225,7 @@
 
 // type
 		if(!is_null($options['type'] )){
-			$sql_parts['where'][] = 'g.type='.$options['type'];
+			$sql_parts['where'][] = 'g.type='.zbx_dbstr($options['type']);
 		}
 
 // templated
@@ -719,22 +719,22 @@
 			'graphid' => $graphid,
 			'name' => zbx_dbstr($graph['name'])
 		);
-		if(isset($graph['width'])) $values['width'] = $graph['width'];
-		if(isset($graph['height'])) $values['height'] = $graph['height'];
-		if(isset($graph['ymin_type'])) $values['ymin_type'] = $graph['ymin_type'];
-		if(isset($graph['ymax_type'])) $values['ymax_type'] = $graph['ymax_type'];
-		if(isset($graph['yaxismin'])) $values['yaxismin'] = $graph['yaxismin'];
-		if(isset($graph['yaxismax'])) $values['yaxismax'] = $graph['yaxismax'];
-		if(isset($graph['ymin_itemid'])) $values['ymin_itemid'] = $graph['ymin_itemid'];
-		if(isset($graph['ymax_itemid'])) $values['ymax_itemid'] = $graph['ymax_itemid'];
-		if(isset($graph['show_work_period'])) $values['show_work_period'] = $graph['show_work_period'];
-		if(isset($graph['show_triggers'])) $values['show_triggers'] = $graph['show_triggers'];
-		if(isset($graph['graphtype'])) $values['graphtype'] = $graph['graphtype'];
-		if(isset($graph['show_legend'])) $values['show_legend'] = $graph['show_legend'];
-		if(isset($graph['show_3d'])) $values['show_3d'] = $graph['show_3d'];
-		if(isset($graph['percent_left'])) $values['percent_left'] = $graph['percent_left'];
-		if(isset($graph['percent_right'])) $values['percent_right'] = $graph['percent_right'];
-		if(isset($graph['templateid'])) $values['templateid'] = $graph['templateid'];
+		if(isset($graph['width'])) $values['width'] = zbx_dbstr($graph['width']);
+		if(isset($graph['height'])) $values['height'] = zbx_dbstr($graph['height']);
+		if(isset($graph['ymin_type'])) $values['ymin_type'] = zbx_dbstr($graph['ymin_type']);
+		if(isset($graph['ymax_type'])) $values['ymax_type'] = zbx_dbstr($graph['ymax_type']);
+		if(isset($graph['yaxismin'])) $values['yaxismin'] = zbx_dbstr($graph['yaxismin']);
+		if(isset($graph['yaxismax'])) $values['yaxismax'] = zbx_dbstr($graph['yaxismax']);
+		if(isset($graph['ymin_itemid'])) $values['ymin_itemid'] = zbx_dbstr($graph['ymin_itemid']);
+		if(isset($graph['ymax_itemid'])) $values['ymax_itemid'] = zbx_dbstr($graph['ymax_itemid']);
+		if(isset($graph['show_work_period'])) $values['show_work_period'] = zbx_dbstr($graph['show_work_period']);
+		if(isset($graph['show_triggers'])) $values['show_triggers'] = zbx_dbstr($graph['show_triggers']);
+		if(isset($graph['graphtype'])) $values['graphtype'] = zbx_dbstr($graph['graphtype']);
+		if(isset($graph['show_legend'])) $values['show_legend'] = zbx_dbstr($graph['show_legend']);
+		if(isset($graph['show_3d'])) $values['show_3d'] = zbx_dbstr($graph['show_3d']);
+		if(isset($graph['percent_left'])) $values['percent_left'] = zbx_dbstr($graph['percent_left']);
+		if(isset($graph['percent_right'])) $values['percent_right'] = zbx_dbstr($graph['percent_right']);
+		if(isset($graph['templateid'])) $values['templateid'] = zbx_dbstr($graph['templateid']);
 
 		$sql = 'INSERT INTO graphs ('.implode(', ', array_keys($values)).') VALUES ('.implode(', ', $values).')';
 		if(!DBexecute($sql))
@@ -745,14 +745,14 @@
 				'gitemid' => get_dbid('graphs_items', 'gitemid'),
 				'graphid' => $graphid,
 			);
-			if(isset($gitem['itemid'])) $values['itemid'] = $gitem['itemid'];
+			if(isset($gitem['itemid'])) $values['itemid'] = zbx_dbstr($gitem['itemid']);
 			if(isset($gitem['color'])) $values['color'] = zbx_dbstr($gitem['color']);
-			if(isset($gitem['drawtype'])) $values['drawtype'] = $gitem['drawtype'];
-			if(isset($gitem['sortorder'])) $values['sortorder'] = $gitem['sortorder'];
-			if(isset($gitem['yaxisside'])) $values['yaxisside'] = $gitem['yaxisside'];
-			if(isset($gitem['calc_fnc'])) $values['calc_fnc'] = $gitem['calc_fnc'];
-			if(isset($gitem['type'])) $values['type'] = $gitem['type'];
-			if(isset($gitem['periods_cnt'])) $values['periods_cnt'] = $gitem['periods_cnt'];
+			if(isset($gitem['drawtype'])) $values['drawtype'] = zbx_dbstr($gitem['drawtype']);
+			if(isset($gitem['sortorder'])) $values['sortorder'] = zbx_dbstr($gitem['sortorder']);
+			if(isset($gitem['yaxisside'])) $values['yaxisside'] = zbx_dbstr($gitem['yaxisside']);
+			if(isset($gitem['calc_fnc'])) $values['calc_fnc'] = zbx_dbstr($gitem['calc_fnc']);
+			if(isset($gitem['type'])) $values['type'] = zbx_dbstr($gitem['type']);
+			if(isset($gitem['periods_cnt'])) $values['periods_cnt'] = zbx_dbstr($gitem['periods_cnt']);
 
 			$sql = 'INSERT INTO graphs_items ('.implode(', ', array_keys($values)).') VALUES ('.implode(', ', $values).')';
 			DBexecute($sql) or self::exception(ZBX_API_ERROR_PARAMETERS, 'DBerror');
@@ -768,7 +768,7 @@
 
 
 		if(isset($graph['gitems'])){
-			if(!DBexecute('DELETE FROM graphs_items WHERE graphid='.$graph['graphid']))
+			if(!DBexecute('DELETE FROM graphs_items WHERE graphid='.zbx_dbstr($graph['graphid'])))
 				self::exception(ZBX_API_ERROR_PARAMETERS, 'DBerror');
 
 			foreach($graph['gitems'] as $inum => $gitem){
Index: frontends/php/api/classes/class.capplication.php
===================================================================
--- frontends/php/api/classes/class.capplication.php	(revision 38884)
+++ frontends/php/api/classes/class.capplication.php	(working copy)
@@ -645,7 +645,7 @@
 			DB::insert('items_applications', $apps_insert);
 
 			foreach($itemids as $inum => $itemid){
-				$db_childs = DBselect('SELECT itemid, hostid FROM items WHERE templateid=' . $itemid);
+				$db_childs = DBselect('SELECT itemid, hostid FROM items WHERE templateid='.zbx_dbstr($itemid));
 
 				while($child = DBfetch($db_childs)){
 					$sql = 'SELECT a1.applicationid ' .
Index: frontends/php/api/classes/class.cscript.php
===================================================================
--- frontends/php/api/classes/class.cscript.php	(revision 38884)
+++ frontends/php/api/classes/class.cscript.php	(working copy)
@@ -343,7 +343,7 @@
 		$sql = 'SELECT scriptid '.
 				' FROM scripts '.
 				' WHERE '.DBin_node('scriptid').
-					' AND name='.$script['name'];
+					' AND name='.zbx_dbstr($script['name']);
 		$res = DBselect($sql);
 		while($script = DBfetch($res)){
 			$scriptids[$script['scriptid']] = $script['scriptid'];
Index: frontends/php/api/classes/class.calert.php
===================================================================
--- frontends/php/api/classes/class.calert.php	(revision 38884)
+++ frontends/php/api/classes/class.calert.php	(working copy)
@@ -282,12 +282,12 @@
 
 // time_from
 		if(!is_null($options['time_from'])){
-			$sql_parts['where'][] = 'a.clock>'.$options['time_from'];
+			$sql_parts['where'][] = 'a.clock>'.zbx_dbstr($options['time_from']);
 		}
 
 // time_till
 		if(!is_null($options['time_till'])){
-			$sql_parts['where'][] = 'a.clock<'.$options['time_till'];
+			$sql_parts['where'][] = 'a.clock<'.zbx_dbstr($options['time_till']);
 		}
 
 // extendoutput
@@ -511,10 +511,10 @@
 			$alertid = get_dbid('alerts', 'alertid');
 			$sql = 'INSERT INTO alerts '.
 					'(alertid, actionid, eventid, userid, mediatypeid, clock, sendto, subject, message, status, retries, error, nextcheck, esc_step, alerttype) '.
-					' VALUES ('.$alertid.','.$alert['actionid'].','.$alert['eventid'].','.$alert['userid'].','.$alert['mediatypeid'].','.
-								$alert['clock'].','.zbx_dbstr($alert['sendto']).','.zbx_dbstr($alert['subject']).','.zbx_dbstr($alert['message']).','.
-								$alert['status'].','.$alert['retries'].','.zbx_dbstr($alert['error']).','.$alert['nextcheck'].','.
-								$alert['esc_step'].','.$alert['alerttype'].' )';
+					' VALUES ('.$alertid.','.zbx_dbstr($alert['actionid']).','.zbx_dbstr($alert['eventid']).','.zbx_dbstr($alert['userid']).','.zbx_dbstr($alert['mediatypeid']).','.
+								zbx_dbstr($alert['clock']).','.zbx_dbstr($alert['sendto']).','.zbx_dbstr($alert['subject']).','.zbx_dbstr($alert['message']).','.
+								zbx_dbstr($alert['status']).','.zbx_dbstr($alert['retries']).','.zbx_dbstr($alert['error']).','.zbx_dbstr($alert['nextcheck']).','.
+								zbx_dbstr($alert['esc_step']).','.zbx_dbstr($alert['alerttype']).' )';
 			$result = DBexecute($sql);
 			if(!$result) break;
 
Index: frontends/php/api/classes/class.ctemplate.php
===================================================================
--- frontends/php/api/classes/class.ctemplate.php	(revision 38884)
+++ frontends/php/api/classes/class.ctemplate.php	(working copy)
@@ -998,7 +998,7 @@
 
 				foreach($template['groups'] as $group){
 					$hostgroupid = get_dbid('hosts_groups', 'hostgroupid');
-					$result = DBexecute("INSERT INTO hosts_groups (hostgroupid, hostid, groupid) VALUES ($hostgroupid, $templateid, {$group['groupid']})");
+					$result = DBexecute('INSERT INTO hosts_groups (hostgroupid, hostid, groupid) VALUES ('.$hostgroupid.','.zbx_dbstr($templateid).','.zbx_dbstr($group['groupid']).')');
 					if(!$result){
 						self::exception(ZBX_API_ERROR_PARAMETERS, 'DBerror');
 					}
@@ -1633,7 +1633,7 @@
 					if(isset($link[$targetid]) && ($link[$targetid] == $templateid)) continue 2;
 				}
 
-				$values = array(get_dbid('hosts_templates', 'hosttemplateid'), $targetid, $templateid);
+				$values = array(get_dbid('hosts_templates', 'hosttemplateid'), zbx_dbstr($targetid), zbx_dbstr($templateid));
 				$sql = 'INSERT INTO hosts_templates VALUES ('. implode(', ', $values) .')';
 				$result = DBexecute($sql);
 
Index: frontends/php/api/classes/class.cdrule.php
===================================================================
--- frontends/php/api/classes/class.cdrule.php	(revision 38884)
+++ frontends/php/api/classes/class.cdrule.php	(working copy)
@@ -588,7 +588,7 @@
 		if($host["status"] == HOST_STATUS_TEMPLATE ){
 			$sql = 'SELECT DISTINCT count(i.hostid) as count
 					FROM checks i
-					WHERE i.hostid<>'.$host['hostid'].
+					WHERE i.hostid<>'.zbx_dbstr($host['hostid']).
 						' AND '.DBcondition('i.checkid', $checkids);
 
 			$host_count = DBfetch(DBselect($sql));
@@ -641,7 +641,7 @@
 
 		$sql = 'SELECT curr.checkid
 				FROM drules_checks gi, checks curr, checks src
-				WHERE gi.druleid='.$druleid.
+				WHERE gi.druleid='.zbx_dbstr($druleid).
 					' AND gi.checkid=curr.checkid
 					AND curr.key_=src.key_
 					AND '.DBcondition('src.checkid', $checks);
@@ -653,7 +653,7 @@
 
 		$sql = 'DELETE
 				FROM drules_checks
-				WHERE druleid='.$druleid.
+				WHERE druleid='.zbx_dbstr($druleid).
 					' AND '.DBcondition('checkid', $gchecks);
 		$result = DBselect($sql);
 
Index: frontends/php/api/classes/class.cmap.php
===================================================================
--- frontends/php/api/classes/class.cmap.php	(revision 38884)
+++ frontends/php/api/classes/class.cmap.php	(working copy)
@@ -674,13 +674,13 @@
 //----
 			$sql = 'UPDATE sysmaps '.
 					' SET name='.zbx_dbstr($map['name']).','.
-						' width='.$map['width'].','.
-						' height='.$map['height'].','.
-						' backgroundid='.$map['backgroundid'].','.
-						' highlight='.$map['highlight'].','.
-						' label_type='.$map['label_type'].','.
-						' label_location='.$map['label_location'].
-					' WHERE sysmapid='.$map['sysmapid'];
+						' width='.zbx_dbstr($map['width']).','.
+						' height='.zbx_dbstr($map['height']).','.
+						' backgroundid='.zbx_dbstr($map['backgroundid']).','.
+						' highlight='.zbx_dbstr($map['highlight']).','.
+						' label_type='.zbx_dbstr($map['label_type']).','.
+						' label_location='.zbx_dbstr($map['label_location']).
+					' WHERE sysmapid='.zbx_dbstr($map['sysmapid']);
 			$result = DBexecute($sql);
 
 			if(!$result) break;
@@ -901,18 +901,18 @@
 
 				$values = array(
 					'selementid' => $selementid,
-					'sysmapid' => $selement['sysmapid'],
-					'elementid' => $selement['elementid'],
-					'elementtype' => $selement['elementtype'],
+					'sysmapid' => zbx_dbstr($selement['sysmapid']),
+					'elementid' => zbx_dbstr($selement['elementid']),
+					'elementtype' => zbx_dbstr($selement['elementtype']),
 					'label' => zbx_dbstr($selement['label']),
-					'label_location' => $selement['label_location'],
-					'iconid_off' => $selement['iconid_off'],
-					'iconid_on' => $selement['iconid_on'],
-					'iconid_unknown' => $selement['iconid_unknown'],
-					'iconid_maintenance' => $selement['iconid_maintenance'],
-					'iconid_disabled' => $selement['iconid_disabled'],
-					'x' => $selement['x'],
-					'y' => $selement['y'],
+					'label_location' => zbx_dbstr($selement['label_location']),
+					'iconid_off' => zbx_dbstr($selement['iconid_off']),
+					'iconid_on' => zbx_dbstr($selement['iconid_on']),
+					'iconid_unknown' => zbx_dbstr($selement['iconid_unknown']),
+					'iconid_maintenance' => zbx_dbstr($selement['iconid_maintenance']),
+					'iconid_disabled' => zbx_dbstr($selement['iconid_disabled']),
+					'x' => zbx_dbstr($selement['x']),
+					'y' => zbx_dbstr($selement['y']),
 					'url' => zbx_dbstr($selement['url'])
 				);
 
@@ -1006,19 +1006,19 @@
 				}
 
 				$result = DBexecute('UPDATE sysmaps_elements '.
-						'SET elementid='.$selement['elementid'].', '.
-							' elementtype='.$selement['elementtype'].', '.
+						'SET elementid='.zbx_dbstr($selement['elementid']).', '.
+							' elementtype='.zbx_dbstr($selement['elementtype']).', '.
 							' label='.zbx_dbstr($selement['label']).', '.
-							' label_location='.$selement['label_location'].', '.
-							' x='.$selement['x'].', '.
-							' y='.$selement['y'].', '.
-							' iconid_off='.$selement['iconid_off'].', '.
-							' iconid_on='.$selement['iconid_on'].', '.
-							' iconid_unknown='.$selement['iconid_unknown'].', '.
-							' iconid_maintenance='.$selement['iconid_maintenance'].', '.
-							' iconid_disabled='.$selement['iconid_disabled'].', '.
+							' label_location='.zbx_dbstr($selement['label_location']).', '.
+							' x='.zbx_dbstr($selement['x']).', '.
+							' y='.zbx_dbstr($selement['y']).', '.
+							' iconid_off='.zbx_dbstr($selement['iconid_off']).', '.
+							' iconid_on='.zbx_dbstr($selement['iconid_on']).', '.
+							' iconid_unknown='.zbx_dbstr($selement['iconid_unknown']).', '.
+							' iconid_maintenance='.zbx_dbstr($selement['iconid_maintenance']).', '.
+							' iconid_disabled='.zbx_dbstr($selement['iconid_disabled']).', '.
 							' url='.zbx_dbstr($selement['url']).
-						' WHERE selementid='.$selement['selementid']);
+						' WHERE selementid='.zbx_dbstr($selement['selementid']));
 
 				if(!$result) self::exception(ZBX_API_ERROR_INTERNAL, 'Map update elements failed');
 
@@ -1120,8 +1120,8 @@
 
 			$linktriggerid = get_dbid('sysmaps_link_triggers', 'linktriggerid');
 			$sql = 'INSERT INTO sysmaps_link_triggers (linktriggerid, linkid, triggerid, drawtype, color) '.
-				' VALUES ('.$linktriggerid.','.$linktrigger['linkid'].','.$linktrigger['triggerid'].', '.
-					$linktrigger['drawtype'].','.zbx_dbstr($linktrigger['color']).')';
+				' VALUES ('.$linktriggerid.','.zbx_dbstr($linktrigger['linkid']).','.zbx_dbstr($linktrigger['triggerid']).', '.
+					zbx_dbstr($linktrigger['drawtype']).','.zbx_dbstr($linktrigger['color']).')';
 			$result = DBexecute($sql);
 			if(!$result){
 				$result = false;
Index: frontends/php/api/classes/class.cuser.php
===================================================================
--- frontends/php/api/classes/class.cuser.php	(revision 38884)
+++ frontends/php/api/classes/class.cuser.php	(working copy)
@@ -463,13 +463,13 @@
 					zbx_dbstr($user['alias']).','.
 					zbx_dbstr(md5($user['passwd'])).','.
 					zbx_dbstr($user['url']).','.
-					$user['autologin'].','.
-					$user['autologout'].','.
+					zbx_dbstr($user['autologin']).','.
+					zbx_dbstr($user['autologout']).','.
 					zbx_dbstr($user['lang']).','.
 					zbx_dbstr($user['theme']).','.
-					$user['refresh'].','.
-					$user['rows_per_page'].','.
-					$user['type'].
+					zbx_dbstr($user['refresh']).','.
+					zbx_dbstr($user['rows_per_page']).','.
+					zbx_dbstr($user['type']).
 				')');
 
 			if($result){
@@ -478,7 +478,7 @@
 					if(!$result) break;
 					$users_groups_id = get_dbid("users_groups","id");
 					$result = DBexecute('INSERT INTO users_groups (id,usrgrpid,userid)'.
-						'values('.$users_groups_id.','.$groupid.','.$userid.')');
+						'values('.$users_groups_id.','.zbx_dbstr($groupid).','.zbx_dbstr($userid).')');
 				}
 			}
 
@@ -487,8 +487,8 @@
 					if(!$result) break;
 					$mediaid = get_dbid('media', 'mediaid');
 					$result = DBexecute('INSERT INTO media (mediaid,userid,mediatypeid,sendto,active,severity,period)'.
-						' VALUES ('.$mediaid.','.$userid.','.$media_data['mediatypeid'].','.
-						zbx_dbstr($media_data['sendto']).','.$media_data['active'].','.$media_data['severity'].','.
+						' VALUES ('.$mediaid.','.zbx_dbstr($userid).','.zbx_dbstr($media_data['mediatypeid']).','.
+						zbx_dbstr($media_data['sendto']).','.zbx_dbstr($media_data['active']).','.zbx_dbstr($media_data['severity']).','.
 						zbx_dbstr($media_data['period']).')');
 				}
 			}
@@ -613,14 +613,14 @@
 						' alias='.zbx_dbstr($user['alias']).', '.
 						' passwd='.zbx_dbstr($user['passwd']).', '.
 						' url='.zbx_dbstr($user['url']).', '.
-						' autologin='.$user['autologin'].', '.
-						' autologout='.$user['autologout'].', '.
+						' autologin='.zbx_dbstr($user['autologin']).', '.
+						' autologout='.zbx_dbstr($user['autologout']).', '.
 						' lang='.zbx_dbstr($user['lang']).', '.
 						' theme='.zbx_dbstr($user['theme']).', '.
-						' refresh='.$user['refresh'].', '.
-						' rows_per_page='.$user['rows_per_page'].', '.
-						' type='.$user['type'].
-					' WHERE userid='.$user['userid'];
+						' refresh='.zbx_dbstr($user['refresh']).', '.
+						' rows_per_page='.zbx_dbstr($user['rows_per_page']).', '.
+						' type='.zbx_dbstr($user['type']).
+					' WHERE userid='.zbx_dbstr($user['userid']);
 
 			$result = DBexecute($sql);
 
@@ -644,7 +644,7 @@
 
 
 			if($result && isset($user['usrgrps']) && !is_null($user['usrgrps'])){
-				DBexecute('DELETE FROM users_groups WHERE userid='.$user['userid']);
+				DBexecute('DELETE FROM users_groups WHERE userid='.zbx_dbstr($user['userid']));
 
 				$options = array(
 					'usrgrpids' => zbx_objectValues($user['usrgrps'], 'usrgrpid'),
@@ -669,7 +669,7 @@
 					}
 
 					$users_groups_id = get_dbid('users_groups', 'id');
-					$result = DBexecute('INSERT INTO users_groups (id, usrgrpid, userid) VALUES ('.$users_groups_id.','.$groupid.','.$user['userid'].')');
+					$result = DBexecute('INSERT INTO users_groups (id, usrgrpid, userid) VALUES ('.$users_groups_id.','.zbx_dbstr($groupid).','.zbx_dbstr($user['userid']).')');
 				}
 			}
 /*
@@ -771,13 +771,13 @@
 		$sql = 'UPDATE users SET '.
 					' passwd='.zbx_dbstr($user['passwd']).', '.
 					' url='.zbx_dbstr($user['url']).', '.
-					' autologin='.$user['autologin'].', '.
-					' autologout='.$user['autologout'].', '.
+					' autologin='.zbx_dbstr($user['autologin']).', '.
+					' autologout='.zbx_dbstr($user['autologout']).', '.
 					' lang='.zbx_dbstr($user['lang']).', '.
 					' theme='.zbx_dbstr($user['theme']).', '.
-					' refresh='.$user['refresh'].', '.
-					' rows_per_page='.$user['rows_per_page'].
-				' WHERE userid='.$user['userid'];
+					' refresh='.zbx_dbstr($user['refresh']).', '.
+					' rows_per_page='.zbx_dbstr($user['rows_per_page']).
+				' WHERE userid='.zbx_dbstr($user['userid']);
 
 		$result = DBexecute($sql);
 
@@ -912,8 +912,8 @@
 				$mediaid = get_dbid('media','mediaid');
 
 				$sql='INSERT INTO media (mediaid,userid,mediatypeid,sendto,active,severity,period) '.
-						' VALUES ('.$mediaid.','.$user['userid'].','.$media['mediatypeid'].','.
-									zbx_dbstr($media['sendto']).','.$media['active'].','.$media['severity'].','.
+						' VALUES ('.$mediaid.','.zbx_dbstr($user['userid']).','.zbx_dbstr($media['mediatypeid']).','.
+									zbx_dbstr($media['sendto']).','.zbx_dbstr($media['active']).','.zbx_dbstr($media['severity']).','.
 									zbx_dbstr($media['period']).')';
 
 				$result = DBexecute($sql);
@@ -1039,12 +1039,12 @@
 				}
 
 				$sql = 'UPDATE media '.
-						' SET mediatypeid='.$media['mediatypeid'].','.
+						' SET mediatypeid='.zbx_dbstr($media['mediatypeid']).','.
 							' sendto='.zbx_dbstr($media['sendto']).','.
-							' active='.$media['active'].','.
-							' severity='.$media['severity'].','.
+							' active='.zbx_dbstr($media['active']).','.
+							' severity='.zbx_dbstr($media['severity']).','.
 							' period='.zbx_dbstr($media['period']).
-						' WHERE mediaid='.$media['mediaid'];
+						' WHERE mediaid='.zbx_dbstr($media['mediaid']);
 				$result = DBexecute($sql);
 				if(!$result){
 					throw new APIException(ZBX_API_ERROR_PARAMETERS, S_CUSER_ERROR_CANT_UPDATE_USER_MEDIAS);
@@ -1255,7 +1255,7 @@
 							' SET attempt_failed='.$attempt['attempt_failed'].','.
 								' attempt_clock='.time().','.
 								' attempt_ip='.zbx_dbstr($ip).
-							' WHERE userid='.$attempt['userid'];
+							' WHERE userid='.zbx_dbstr($attempt['userid']);
 					DBexecute($sql);
 				}
 			}
Index: frontends/php/api/classes/class.cevent.php
===================================================================
--- frontends/php/api/classes/class.cevent.php	(revision 38884)
+++ frontends/php/api/classes/class.cevent.php	(working copy)
@@ -239,12 +239,12 @@
 
 // object
 		if(!is_null($options['object'])){
-			$sql_parts['where']['o'] = 'e.object='.$options['object'];
+			$sql_parts['where']['o'] = 'e.object='.zbx_dbstr($options['object']);
 		}
 
 // source
 		if(!is_null($options['source'])){
-			$sql_parts['where'][] = 'e.source='.$options['source'];
+			$sql_parts['where'][] = 'e.source='.zbx_dbstr($options['source']);
 		}
 // acknowledged
 		if(!is_null($options['acknowledged'])){
@@ -256,19 +256,19 @@
 		}
 // time_from
 		if(!is_null($options['time_from'])){
-			$sql_parts['where'][] = 'e.clock>='.$options['time_from'];
+			$sql_parts['where'][] = 'e.clock>='.zbx_dbstr($options['time_from']);
 		}
 // time_till
 		if(!is_null($options['time_till'])){
-			$sql_parts['where'][] = 'e.clock<='.$options['time_till'];
+			$sql_parts['where'][] = 'e.clock<='.zbx_dbstr($options['time_till']);
 		}
 // eventid_from
 		if(!is_null($options['eventid_from'])){
-			$sql_parts['where'][] = 'e.eventid>='.$options['eventid_from'];
+			$sql_parts['where'][] = 'e.eventid>='.zbx_dbstr($options['eventid_from']);
 		}
 // eventid_till
 		if(!is_null($options['eventid_till'])){
-			$sql_parts['where'][] = 'e.eventid<='.$options['eventid_till'];
+			$sql_parts['where'][] = 'e.eventid<='.zbx_dbstr($options['eventid_till']);
 		}
 // value
 		if(!is_null($options['value'])){
@@ -575,12 +575,12 @@
 			$eventid = get_dbid('events','eventid');
 			$sql = 'INSERT INTO events (eventid, source, object, objectid, clock, value, acknowledged) '.
 					' VALUES ('.$eventid.','.
-								$event['source'].','.
-								$event['object'].','.
-								$event['objectid'].','.
-								$event['clock'].','.
-								$event['value'].','.
-								$event['acknowledged'].
+								zbx_dbstr($event['source']).','.
+								zbx_dbstr($event['object']).','.
+								zbx_dbstr($event['objectid']).','.
+								zbx_dbstr($event['clock']).','.
+								zbx_dbstr($event['value']).','.
+								zbx_dbstr($event['acknowledged']).
 							')';
 			$result = DBexecute($sql);
 			if(!$result) break;
@@ -716,26 +716,26 @@
 					' WHERE e.object='.EVENT_OBJECT_TRIGGER.
 						' AND e.objectid='.$event['objectid'].
 						' AND e.value='.$val.
-						' AND e.eventid<'.$event['eventid'].
+						' AND e.eventid<'.zbx_dbstr($event['eventid']).
 					' ORDER BY e.object DESC,e.objectid DESC,e.eventid DESC';
 				$first = DBfetch(DBselect($sql, 1));
-				$first_sql = $first ? ' AND e.eventid>'.$first['eventid'] : '';
+				$first_sql = $first ? ' AND e.eventid>'.zbx_dbstr($first['eventid']) : '';
 
 				$sql = 'SELECT e.object,e.objectid,e.eventid'.
 					' FROM events e'.
 					' WHERE e.object='.EVENT_OBJECT_TRIGGER.
-						' AND e.objectid='.$event['objectid'].
-						' AND e.value='.$val.
-						' AND e.eventid>'.$event['eventid'].
+						' AND e.objectid='.zbx_dbstr($event['objectid']).
+						' AND e.value='.zbx_dbstr($val).
+						' AND e.eventid>'.zbx_dbstr($event['eventid']).
 					' ORDER BY e.object,e.objectid,e.eventid';
 				$last = DBfetch(DBselect($sql, 1));
-				$last_sql = $last ? ' AND e.eventid<'.$last['eventid'] : '';
+				$last_sql = $last ? ' AND e.eventid<'.zbx_dbstr($last['eventid']) : '';
 
 				$sql = 'SELECT e.eventid'.
 					' FROM events e'.
 					' WHERE e.object='.EVENT_OBJECT_TRIGGER.
-						' AND e.objectid='.$event['objectid'].
-						' AND e.value='.$event['value'].
+						' AND e.objectid='.zbx_dbstr($event['objectid']).
+						' AND e.value='.zbx_dbstr($event['value']).
 						$first_sql.
 						$last_sql;
 
Index: frontends/php/api/classes/class.chostgroup.php
===================================================================
--- frontends/php/api/classes/class.chostgroup.php	(revision 38884)
+++ frontends/php/api/classes/class.chostgroup.php	(working copy)
@@ -697,7 +697,7 @@
 				$groupsNames[$group['name']] = array('groupid' => $group['groupid']);
 //---
 
-				$sql = 'UPDATE groups SET name='.zbx_dbstr($group['name']).' WHERE groupid='.$group['groupid'];
+				$sql = 'UPDATE groups SET name='.zbx_dbstr($group['name']).' WHERE groupid='.zbx_dbstr($group['groupid']);
 				if(!DBexecute($sql)){
 					self::exception(ZBX_API_ERROR_PARAMETERS, 'DBerror');
 				}
@@ -812,7 +812,7 @@
 				foreach($objectids as $hostid){
 					if(isset($linked[$groupid][$hostid])) continue;
 					$hostgroupid = get_dbid('hosts_groups', 'hostgroupid');
-					$result = DBexecute("INSERT INTO hosts_groups (hostgroupid, hostid, groupid) VALUES ($hostgroupid, $hostid, $groupid)");
+					$result = DBexecute('INSERT INTO hosts_groups (hostgroupid, hostid, groupid) VALUES ('.zbx_dbstr($hostgroupid).','.zbx_dbstr($hostid).','.zbx_dbstr($groupid).')');
 					if(!$result){
 						self::exception(ZBX_API_ERROR_PARAMETERS, 'DBerror');
 					}
@@ -984,7 +984,7 @@
 			foreach($groupids as $gnum => $groupid){
 				foreach($objectids_to_link as $objectid){
 					$hostgroupid = get_dbid('hosts_groups', 'hostgroupid');
-					$result = DBexecute("INSERT INTO hosts_groups (hostgroupid, hostid, groupid) VALUES ($hostgroupid, $objectid, $groupid)");
+					$result = DBexecute('INSERT INTO hosts_groups (hostgroupid, hostid, groupid) VALUES ('.zbx_dbstr($hostgroupid).','.zbx_dbstr($objectid).','.zbx_dbstr($groupid).')');
 					if(!$result){
 						self::exception(ZBX_API_ERROR_PARAMETERS, 'DBerror');
 					}
Index: frontends/php/api/classes/class.cusergroup.php
===================================================================
--- frontends/php/api/classes/class.cusergroup.php	(revision 38884)
+++ frontends/php/api/classes/class.cusergroup.php	(working copy)
@@ -147,7 +147,7 @@
 
 // status
 		if(!is_null($options['status'])){
-			$sql_parts['where'][] = 'g.users_status='.$options['status'];
+			$sql_parts['where'][] = 'g.users_status='.zbx_dbstr($options['status']);
 		}
 
 // with_gui_access
Index: frontends/php/api/classes/class.chistory.php
===================================================================
--- frontends/php/api/classes/class.chistory.php	(revision 38884)
+++ frontends/php/api/classes/class.chistory.php	(working copy)
@@ -172,13 +172,13 @@
 // time_from
 		if(!is_null($options['time_from'])){
 			$sql_parts['select']['clock'] = 'h.clock';
-			$sql_parts['where']['clock_from'] = 'h.clock>='.$options['time_from'];
+			$sql_parts['where']['clock_from'] = 'h.clock>='.zbx_dbstr($options['time_from']);
 		}
 
 // time_till
 		if(!is_null($options['time_till'])){
 			$sql_parts['select']['clock'] = 'h.clock';
-			$sql_parts['where']['clock_till'] = 'h.clock<='.$options['time_till'];
+			$sql_parts['where']['clock_till'] = 'h.clock<='.zbx_dbstr($options['time_till']);
 		}
 
 // filter
Index: frontends/php/api/classes/class.ctrigger.php
===================================================================
--- frontends/php/api/classes/class.ctrigger.php	(revision 38884)
+++ frontends/php/api/classes/class.ctrigger.php	(working copy)
@@ -384,12 +384,12 @@
 
 // lastChangeSince
 		if(!is_null($options['lastChangeSince'])){
-			$sql_parts['where']['lastchangesince'] = 't.lastchange>'.$options['lastChangeSince'];
+			$sql_parts['where']['lastchangesince'] = 't.lastchange>'.zbx_dbstr($options['lastChangeSince']);
 		}
 
 // lastChangeTill
 		if(!is_null($options['lastChangeTill'])){
-			$sql_parts['where']['lastchangetill'] = 't.lastchange<'.$options['lastChangeTill'];
+			$sql_parts['where']['lastchangetill'] = 't.lastchange<'.zbx_dbstr($options['lastChangeTill']);
 		}
 
 // withUnacknowledgedEvents
@@ -517,7 +517,7 @@
 
 // min_severity
 		if(!is_null($options['min_severity'])){
-			$sql_parts['where'][] = 't.priority>='.$options['min_severity'];
+			$sql_parts['where'][] = 't.priority>='.zbx_dbstr($options['min_severity']);
 		}
 
 // output
Index: frontends/php/api/classes/class.chost.php
===================================================================
--- frontends/php/api/classes/class.chost.php	(revision 38884)
+++ frontends/php/api/classes/class.chost.php	(working copy)
@@ -1102,19 +1102,19 @@
 				$result = DBexecute('INSERT INTO hosts (hostid, proxy_hostid, host, port, status, useip, dns, ip, disable_until, available,'.
 					'useipmi,ipmi_port,ipmi_authtype,ipmi_privilege,ipmi_username,ipmi_password,ipmi_ip) VALUES ('.
 					$hostid.','.
-					$host['proxy_hostid'].','.
+					zbx_dbstr($host['proxy_hostid']).','.
 					zbx_dbstr($host['host']).','.
-					$host['port'].','.
-					$host['status'].','.
-					$host['useip'].','.
+					zbx_dbstr($host['port']).','.
+					zbx_dbstr($host['status']).','.
+					zbx_dbstr($host['useip']).','.
 					zbx_dbstr($host['dns']).','.
 					zbx_dbstr($host['ip']).
 					',0,'.
 					HOST_AVAILABLE_UNKNOWN.','.
-					$host['useipmi'].','.
-					$host['ipmi_port'].','.
-					$host['ipmi_authtype'].','.
-					$host['ipmi_privilege'].','.
+					zbx_dbstr($host['useipmi']).','.
+					zbx_dbstr($host['ipmi_port']).','.
+					zbx_dbstr($host['ipmi_authtype']).','.
+					zbx_dbstr($host['ipmi_privilege']).','.
 					zbx_dbstr($host['ipmi_username']).','.
 					zbx_dbstr($host['ipmi_password']).','.
 					zbx_dbstr($host['ipmi_ip']).')'
@@ -1125,7 +1125,7 @@
 
 				foreach($host['groups'] as $group){
 					$hostgroupid = get_dbid('hosts_groups', 'hostgroupid');
-					$result = DBexecute("INSERT INTO hosts_groups (hostgroupid, hostid, groupid) VALUES ($hostgroupid, $hostid, {$group['groupid']})");
+					$result = DBexecute('INSERT INTO hosts_groups (hostgroupid, hostid, groupid) VALUES ('.zbx_dbstr($hostgroupid).','.zbx_dbstr($hostid).','.zbx_dbstr($group['groupid']).')');
 					if(!$result){
 						self::exception(ZBX_API_ERROR_PARAMETERS, 'DBerror');
 					}
Index: frontends/php/api/classes/class.cgraphitem.php
===================================================================
--- frontends/php/api/classes/class.cgraphitem.php	(revision 38884)
+++ frontends/php/api/classes/class.cgraphitem.php	(working copy)
@@ -131,7 +131,7 @@
 
 // type
 		if(!is_null($options['type'] )){
-			$sql_parts['where'][] = 'gi.type='.$options['type'];
+			$sql_parts['where'][] = 'gi.type='.zbx_dbstr($options['type']);
 		}
 
 // output
@@ -274,8 +274,8 @@
 
 		$sql = 'SELECT gi.gitemid '.
 				' FROM graphs_items gi '.
-				' WHERE gi.itemid='.$gitem_data['itemid'].
-					' AND gi.graphid='.$gitem_data['graphid'].
+				' WHERE gi.itemid='.zbx_dbstr($gitem_data['itemid']).
+					' AND gi.graphid='.zbx_dbstr($gitem_data['graphid']);
 		$db_res = DBselect($sql);
 		while($gitem = DBfetch($db_res)){
 			$gitemids[$gitem['gitemid']] = $gitem['gitemid'];
Index: frontends/php/api/classes/class.cimage.php
===================================================================
--- frontends/php/api/classes/class.cimage.php	(revision 38884)
+++ frontends/php/api/classes/class.cimage.php	(working copy)
@@ -324,9 +324,9 @@
 
 				$imageid = get_dbid('images','imageid');
 				$values = array(
-					'imageid' => $imageid,
+					'imageid' => zbx_dbstr($imageid),
 					'name' => zbx_dbstr($image['name']),
-					'imagetype' => $image['imagetype'],
+					'imagetype' => zbx_dbstr($image['imagetype'])
 				);
 
 				if($DB['TYPE'] == 'ORACLE'){
@@ -432,7 +432,7 @@
 
 				$values = array();
 				if(isset($image['name'])) $values['name'] = zbx_dbstr($image['name']);
-				if(isset($image['imagetype'])) $values['imagetype'] = $image['imagetype'];
+				if(isset($image['imagetype'])) $values['imagetype'] = zbx_dbstr($image['imagetype']);
 
 				if(isset($image['image'])){
 // Decode BASE64
@@ -448,7 +448,7 @@
 						$values['image'] = zbx_dbstr($image['image']);
 					}
 					else if($DB['TYPE'] == 'ORACLE'){
-						$sql = 'SELECT image FROM images WHERE imageid = '.$image['imageid'].' FOR UPDATE';
+						$sql = 'SELECT image FROM images WHERE imageid = '.zbx_dbstr($image['imageid']).' FOR UPDATE';
 
 						if(!$stmt = oci_parse($DB['DB'], $sql)){
 							$e = oci_error($DB['DB']);
@@ -469,7 +469,7 @@
 						$row['IMAGE']->free();
 					}
 					else if($DB['TYPE'] == 'IBM_DB2'){
-						$stmt = db2_prepare($DB['DB'], 'UPDATE images SET image=? WHERE imageid='.$image['imageid']);
+						$stmt = db2_prepare($DB['DB'], 'UPDATE images SET image=? WHERE imageid='.zbx_dbstr($image['imageid']));
 
 						if(!$stmt){
 							self::exception(ZBX_API_ERROR_PARAMETERS, db2_conn_errormsg($DB['DB']));
@@ -489,7 +489,7 @@
 				foreach($values as $field => $value){
 					$sql_upd[] = $field.'='.$value;
 				}
-				$sql = 'UPDATE images SET '.implode(', ', $sql_upd).' WHERE imageid='.$image['imageid'];
+				$sql = 'UPDATE images SET '.implode(', ', $sql_upd).' WHERE imageid='.zbx_dbstr($image['imageid']);
 				$result = DBexecute($sql);
 
 				if(!$result){
