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)
@@ -333,7 +333,7 @@
 			zbx_value2array($options['filter']);
 
 			if(isset($options['filter']['templateid'])){
-				$sql_parts['where']['templateid'] = 'h.hostid='.$options['filter']['templateid'];
+				$sql_parts['where']['templateid'] = 'h.hostid='.zbx_dbstr($options['filter']['templateid']);
 			}
 			if(isset($options['filter']['host'])){
 				$sql_parts['where']['host'] = 'h.host='.zbx_dbstr($options['filter']['host']);
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)
@@ -146,7 +146,7 @@
 			zbx_value2array($options['filter']);
 
 			if(isset($options['filter']['sysmapid'])){
-				$sql_parts['where']['sysmapid'] = 's.sysmapid='.$options['filter']['sysmapid'];
+				$sql_parts['where']['sysmapid'] = 's.sysmapid='.zbx_dbstr($options['filter']['sysmapid']);
 			}
 			if(isset($options['filter']['name'])){
 				$sql_parts['where']['name'] = 's.name='.zbx_dbstr($options['filter']['name']);
@@ -530,8 +530,8 @@
 
 			$sysmapid=get_dbid('sysmaps','sysmapid');
 			$result=DBexecute('INSERT INTO sysmaps (sysmapid,name,width,height,backgroundid,highlight,label_type,label_location)'.
-					' VALUES ('.$sysmapid.','.zbx_dbstr($map['name']).','.$map['width'].','.$map['height'].','.
-								$map['backgroundid'].','.$map['highlight'].','.$map['label_type'].','.$map['label_location'].')');
+					' VALUES ('.$sysmapid.','.zbx_dbstr($map['name']).','.zbx_dbstr($map['width']).','.zbx_dbstr($map['height']).','.
+						zbx_dbstr($map['backgroundid']).','.zbx_dbstr($map['highlight']).','.zbx_dbstr($map['label_type']).','.zbx_dbstr($map['label_location']).')');
 
 			if(!$result) break;
 
@@ -616,13 +616,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;
@@ -916,8 +916,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.caction.php
===================================================================
--- frontends/php/api/classes/class.caction.php	(revision 38884)
+++ frontends/php/api/classes/class.caction.php	(working copy)
@@ -332,27 +332,27 @@
 
 // eventsource
 		if(!is_null($options['eventsource'])){
-			$sql_parts['where'][] = 'a.eventsource='.$options['eventsource'];
+			$sql_parts['where'][] = 'a.eventsource='.zbx_dbstr($options['eventsource']);
 		}
 
 // evaltype
 		if(!is_null($options['evaltype'])){
-			$sql_parts['where'][] = 'a.evaltype='.$options['evaltype'];
+			$sql_parts['where'][] = 'a.evaltype='.zbx_dbstr($options['evaltype']);
 		}
 
 // status
 		if(!is_null($options['status'])){
-			$sql_parts['where'][] = 'a.status='.$options['status'];
+			$sql_parts['where'][] = 'a.status='.zbx_dbstr($options['status']);
 		}
 
 // esc_period
 		if(!is_null($options['esc_period'])){
-			$sql_parts['where'][] = 'a.esc_period>'.$options['esc_period'];
+			$sql_parts['where'][] = 'a.esc_period>'.zbx_dbstr($options['esc_period']);
 		}
 
 // recovery_msg
 		if(!is_null($options['recovery_msg'])){
-			$sql_parts['where'][] = 'a.recovery_msg<'.$options['recovery_msg'];
+			$sql_parts['where'][] = 'a.recovery_msg<'.zbx_dbstr($options['recovery_msg']);
 		}
 
 // extendoutput
@@ -566,15 +566,15 @@
 				$values = array(
 					'actionid' => $actionid,
 					'name' => zbx_dbstr($action['name']),
-					'eventsource' => $action['eventsource'],
-					'esc_period' => $action['esc_period'],
+					'eventsource' => zbx_dbstr($action['eventsource']),
+					'esc_period' => zbx_dbstr($action['esc_period']),
 					'def_shortdata' => zbx_dbstr($action['def_shortdata']),
 					'def_longdata' => zbx_dbstr($action['def_longdata']),
 					'recovery_msg' => zbx_dbstr($action['recovery_msg']),
 					'r_shortdata' => zbx_dbstr($action['r_shortdata']),
 					'r_longdata' => zbx_dbstr($action['r_longdata']),
-					'evaltype' => $action['evaltype'],
-					'status' => $action['status']
+					'evaltype' => zbx_dbstr($action['evaltype']),
+					'status' => zbx_dbstr($action['status'])
 				);
 
 
@@ -721,9 +721,9 @@
 			$conditionid = get_dbid('conditions','conditionid');
 			$values = array(
 				'conditionid' => $conditionid,
-				'actionid' => $condition['actionid'],
-				'conditiontype' => $condition['conditiontype'],
-				'operator' => $condition['operator'],
+				'actionid' => zbx_dbstr($condition['actionid']),
+				'conditiontype' => zbx_dbstr($condition['conditiontype']),
+				'operator' => zbx_dbstr($condition['operator']),
 				'value' => zbx_dbstr($condition['value'])
 			);
 
@@ -809,17 +809,17 @@
 			$operationid = get_dbid('operations','operationid');
 			$values = array(
 				'operationid' => $operationid,
-				'actionid' => $operation['actionid'],
-				'operationtype' => $operation['operationtype'],
-				'object' => $operation['object'],
-				'objectid' => $operation['objectid'],
-				'shortdata' => zbx_dbstr($operation['shortdata']),
-				'longdata' => zbx_dbstr($operation['longdata']),
-				'esc_period' => $operation['esc_period'],
-				'esc_step_from' => $operation['esc_step_from'],
-				'esc_step_to' => $operation['esc_step_to'],
-				'default_msg' => $operation['default_msg'],
-				'evaltype' => $operation['evaltype']
+				'actionid' => zbx_dbstr($operation['actionid']),
+				'operationtype' => zbx_dbstr($operation['operationtype']),
+				'object' => zbx_dbstr($operation['object']),
+				'objectid' => zbx_dbstr($operation['objectid']),
+				'shortdata' => zbx_dbstr(zbx_dbstr($operation['shortdata'])),
+				'longdata' => zbx_dbstr(zbx_dbstr($operation['longdata'])),
+				'esc_period' => zbx_dbstr($operation['esc_period']),
+				'esc_step_from' => zbx_dbstr($operation['esc_step_from']),
+				'esc_step_to' => zbx_dbstr($operation['esc_step_to']),
+				'default_msg' => zbx_dbstr($operation['default_msg']),
+				'evaltype' => zbx_dbstr($operation['evaltype'])
 			);
 
 			$result = DBexecute('INSERT INTO operations ('.implode(',', array_keys($values)).')'.
@@ -833,8 +833,8 @@
 				$result &= (bool) DBexecute('INSERT INTO opconditions (opconditionid,operationid,conditiontype,operator,value)'.
 					' values ('.$opconditionid.','.
 						$operationid.','.
-						$opcondition['conditiontype'].','.
-						$opcondition['operator'].','.
+						zbx_dbstr($opcondition['conditiontype']).','.
+						zbx_dbstr($opcondition['operator']).','.
 						zbx_dbstr($opcondition['value']).
 					')');
 			}
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)
@@ -425,7 +425,7 @@
 			zbx_value2array($options['filter']);
 
 			if(isset($options['filter']['hostid']) && !is_null($options['filter']['hostid'])){
-				$sql_parts['where']['hostid'] = 'h.hostid='.$options['filter']['hostid'];
+				$sql_parts['where']['hostid'] = 'h.hostid='.zbx_dbstr($options['filter']['hostid']);
 			}
 
 			if(isset($options['filter']['host']) && !is_null($options['filter']['host'])){
@@ -1036,19 +1036,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']).')'
@@ -1324,17 +1324,17 @@
 			}
 
 			$sql_set = array();
-			if(isset($data['proxy_hostid'])) $sql_set[] = 'proxy_hostid='.$data['proxy_hostid'];
+			if(isset($data['proxy_hostid'])) $sql_set[] = 'proxy_hostid='.zbx_dbstr($data['proxy_hostid']);
 			if(isset($data['host'])) $sql_set[] = 'host='.zbx_dbstr($data['host']);
-			if(isset($data['port'])) $sql_set[] = 'port='.$data['port'];
-			if(isset($data['status'])) $sql_set[] = 'status='.$data['status'];
-			if(isset($data['useip'])) $sql_set[] = 'useip='.$data['useip'];
+			if(isset($data['port'])) $sql_set[] = 'port='.zbx_dbstr($data['port']);
+			if(isset($data['status'])) $sql_set[] = 'status='.zbx_dbstr($data['status']);
+			if(isset($data['useip'])) $sql_set[] = 'useip='.zbx_dbstr($data['useip']);
 			if(isset($data['dns'])) $sql_set[] = 'dns='.zbx_dbstr($data['dns']);
 			if(isset($data['ip'])) $sql_set[] = 'ip='.zbx_dbstr($data['ip']);
-			if(isset($data['useipmi'])) $sql_set[] = 'useipmi='.$data['useipmi'];
-			if(isset($data['ipmi_port'])) $sql_set[] = 'ipmi_port='.$data['ipmi_port'];
-			if(isset($data['ipmi_authtype'])) $sql_set[] = 'ipmi_authtype='.$data['ipmi_authtype'];
-			if(isset($data['ipmi_privilege'])) $sql_set[] = 'ipmi_privilege='.$data['ipmi_privilege'];
+			if(isset($data['useipmi'])) $sql_set[] = 'useipmi='.zbx_dbstr($data['useipmi']);
+			if(isset($data['ipmi_port'])) $sql_set[] = 'ipmi_port='.zbx_dbstr($data['ipmi_port']);
+			if(isset($data['ipmi_authtype'])) $sql_set[] = 'ipmi_authtype='.zbx_dbstr($data['ipmi_authtype']);
+			if(isset($data['ipmi_privilege'])) $sql_set[] = 'ipmi_privilege='.zbx_dbstr($data['ipmi_privilege']);
 			if(isset($data['ipmi_username'])) $sql_set[] = 'ipmi_username='.zbx_dbstr($data['ipmi_username']);
 			if(isset($data['ipmi_password'])) $sql_set[] = 'ipmi_password='.zbx_dbstr($data['ipmi_password']);
 			if(isset($data['ipmi_ip'])) $sql_set[] = 'ipmi_ip='.zbx_dbstr($data['ipmi_ip']);
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)
@@ -149,7 +149,7 @@
 
 // type
 		if(!is_null($options['type'])){
-			$sql_parts['where'][] = 'u.type='.$options['type'];
+			$sql_parts['where'][] = 'u.type='.zbx_dbstr($options['type']);
 		}
 
 
@@ -703,13 +703,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){
@@ -718,7 +718,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).')');
 				}
 			}
 
@@ -727,8 +727,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']).')');
 				}
 			}
@@ -853,14 +853,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);
 
@@ -884,7 +884,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']));
 
 				$usrgrps = CUserGroup::get(array(
 					'usrgrpids' => zbx_objectValues($user['usrgrps'], 'usrgrpid'),
@@ -907,7 +907,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']).')');
 				}
 			}
 /*
@@ -1009,13 +1009,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);
 
@@ -1146,8 +1146,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.','.$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);
@@ -1276,12 +1276,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, 'Can\'t update user media');
Index: frontends/php/api/classes/class.cscreen.php
===================================================================
--- frontends/php/api/classes/class.cscreen.php	(revision 38884)
+++ frontends/php/api/classes/class.cscreen.php	(working copy)
@@ -130,7 +130,7 @@
 			zbx_value2array($options['filter']);
 
 			if(isset($options['filter']['screenid'])){
-				$sql_parts['where']['screenid'] = 's.screenid='.$options['filter']['screenid'];
+				$sql_parts['where']['screenid'] = 's.screenid='.zbx_dbstr($options['filter']['screenid']);
 			}
 			if(isset($options['filter']['name'])){
 				$sql_parts['where']['name'] = 's.name='.zbx_dbstr($options['filter']['name']);
@@ -503,8 +503,8 @@
 				$values = array(
 					'screenid' => $screenid,
 					'name' => zbx_dbstr($screen['name']),
-					'hsize' => $screen['hsize'],
-					'vsize' => $screen['vsize']
+					'hsize' => zbx_dbstr($screen['hsize']),
+					'vsize' => zbx_dbstr($screen['vsize'])
 				);
 				$sql = 'INSERT INTO screens ('.implode(',',array_keys($values)).') '.
 						' VALUES ('.implode(',',array_values($values)).')';
@@ -602,13 +602,13 @@
 
 				$values = array(
 					'name' => zbx_dbstr($screen['name']),
-					'hsize' => $screen['hsize'],
-					'vsize' => $screen['vsize']
+					'hsize' => zbx_dbstr($screen['hsize']),
+					'vsize' => zbx_dbstr($screen['vsize'])
 				);
 
 				$sql = 'UPDATE screens '.
 						' SET '.zbx_implodeHash(',','=',$values).
-						' WHERE	screenid='.$screen['screenid'];
+						' WHERE	screenid='.zbx_dbstr($screen['screenid']);
 				$result = DBexecute($sql);
 
 // Screen items
@@ -779,21 +779,21 @@
 					$screenitemid = get_dbid('screens_items', 'screenitemid');
 					$values = array(
 						'screenitemid' => $screenitemid,
-						'screenid' => $screenid,
-						'resourcetype' => $screenItem['resourcetype'],
-						'resourceid' => $screenItem['resourceid'],
-						'width' => $screenItem['width'],
-						'height' => $screenItem['height'],
-						'x' => $screenItem['x'],
-						'y' => $screenItem['y'],
-						'colspan' => $screenItem['colspan'],
-						'rowspan' => $screenItem['rowspan'],
-						'elements' => $screenItem['elements'],
-						'valign' => $screenItem['valign'],
-						'halign' => $screenItem['halign'],
-						'style' => $screenItem['style'],
+						'screenid' => zbx_dbstr($screenid),
+						'resourcetype' => zbx_dbstr($screenItem['resourcetype']),
+						'resourceid' => zbx_dbstr($screenItem['resourceid']),
+						'width' => zbx_dbstr($screenItem['width']),
+						'height' => zbx_dbstr($screenItem['height']),
+						'x' => zbx_dbstr($screenItem['x']),
+						'y' => zbx_dbstr($screenItem['y']),
+						'colspan' => zbx_dbstr($screenItem['colspan']),
+						'rowspan' => zbx_dbstr($screenItem['rowspan']),
+						'elements' => zbx_dbstr($screenItem['elements']),
+						'valign' => zbx_dbstr($screenItem['valign']),
+						'halign' => zbx_dbstr($screenItem['halign']),
+						'style' => zbx_dbstr($screenItem['style']),
 						'url' => zbx_dbstr($screenItem['url']),
-						'dynamic' => $screenItem['dynamic']
+						'dynamic' => zbx_dbstr($screenItem['dynamic'])
 					);
 
 
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)
@@ -130,7 +130,7 @@
 		}
 // type
 		if(!is_null($options['type'] )){
-			$sql_parts['where'][] = 'gi.type='.$options['type'];
+			$sql_parts['where'][] = 'gi.type='.zbx_dbstr($options['type']);
 		}
 // extendoutput
 		if($options['output'] == API_OUTPUT_EXTEND){
@@ -249,8 +249,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.cevent.php
===================================================================
--- frontends/php/api/classes/class.cevent.php	(revision 38884)
+++ frontends/php/api/classes/class.cevent.php	(working copy)
@@ -205,7 +205,7 @@
 		}
 // object
 		if(!is_null($options['object'])){
-			$sql_parts['where']['o'] = 'e.object='.$options['object'];
+			$sql_parts['where']['o'] = 'e.object='.zbx_dbstr($options['object']);
 		}
 // triggerids
 		if(!is_null($options['triggerids']) && ($options['object'] == EVENT_OBJECT_TRIGGER)){
@@ -214,7 +214,7 @@
 		}
 // 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'])){
@@ -226,11 +226,11 @@
 		}
 // 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']);
 		}
 // value
 		if(!is_null($options['value'])){
@@ -502,12 +502,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;
@@ -625,7 +625,7 @@
 			foreach($events as $enum => $event){
 				$acknowledgeid = get_dbid('acknowledges', 'acknowledgeid');
 				$result = DBexecute('INSERT INTO acknowledges (acknowledgeid, userid, eventid, clock, message)'.
-					' VALUES ('.$acknowledgeid.','.$USER_DETAILS['userid'].','.$event['eventid'].','.$time.','.$message.')');
+					' VALUES ('.$acknowledgeid.','.$USER_DETAILS['userid'].','.zbx_dbstr($event['eventid']).','.$time.','.$message.')');
 
 				if(!$result)
 					break;
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)
@@ -152,13 +152,13 @@
 			zbx_value2array($options['filter']);
 
 			if(isset($options['filter']['imageid']))
-				$sql_parts['where']['imageid'] = 'i.imageid='.$options['filter']['imageid'];
+				$sql_parts['where']['imageid'] = 'i.imageid='.zbx_dbstr($options['filter']['imageid']);
 
 			if(isset($options['filter']['name']))
 				$sql_parts['where']['name'] = 'i.name='.zbx_dbstr($options['filter']['name']);
 
 			if(isset($options['filter']['imagetype']))
-				$sql_parts['where']['imagetype'] = 'i.imagetype='.$options['filter']['imagetype'];
+				$sql_parts['where']['imagetype'] = 'i.imagetype='.zbx_dbstr($options['filter']['imagetype']);
 		}
 
 // order
@@ -361,7 +361,7 @@
 				if($DB['TYPE'] == 'POSTGRESQL'){
 					$image['image'] = pg_escape_bytea($image['image']);
 					$sql = 'INSERT INTO images (imageid, name, imagetype, image) '.
-									' VALUES ('.$imageid.','.zbx_dbstr($image['name']).','.$image['imagetype'].",'".$image['image']."')";
+									' VALUES ('.$imageid.','.zbx_dbstr($image['name']).','.zbx_dbstr($image['imagetype']).",'".$image['image']."')";
 					$result = (bool) DBexecute($sql);
 				}
 				else if($DB['TYPE'] == 'ORACLE'){
@@ -369,7 +369,7 @@
 					$lobimage = OCINewDescriptor($DB['DB'], OCI_D_LOB);
 
 					$stid = OCIParse($DB['DB'], 'INSERT INTO images (imageid,name,imagetype,image)'.
-						' VALUES ('.$imageid.','.zbx_dbstr($image['name']).','.$image['imagetype'].",EMPTY_BLOB())".
+						' VALUES ('.$imageid.','.zbx_dbstr($image['name']).','.zbx_dbstr($image['imagetype']).",EMPTY_BLOB())".
 						' RETURN image INTO :image');
 
 					if(!$stid){
@@ -397,7 +397,7 @@
 					$values = array(
 						'imageid' => $imageid,
 						'name' => zbx_dbstr($image['name']),
-						'imagetype' => $image['imagetype'],
+						'imagetype' => zbx_dbstr($image['imagetype']),
 						'image' => zbx_dbstr($image['image'])
 					);
 
Index: frontends/php/api/classes/class.cmaintenance.php
===================================================================
--- frontends/php/api/classes/class.cmaintenance.php	(revision 38884)
+++ frontends/php/api/classes/class.cmaintenance.php	(working copy)
@@ -377,7 +377,7 @@
 
 		$sql = 'SELECT m.maintenanceid '.
 				' FROM maintenances m '.
-				' WHERE m.name='.$maintenance['name'];
+				' WHERE m.name='.zbx_dbstr($maintenance['name']);
 		$res = DBselect($sql);
 		while($maintenance = DBfetch($res)){
 			$maintenanceids[$maintenance['maintenanceid']] = $maintenance['maintenanceid'];
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)
@@ -272,7 +272,7 @@
 			zbx_value2array($options['filter']);
 
 			if(isset($options['filter']['groupid']))
-				$sql_parts['where']['groupid'] = 'g.groupid='.$options['filter']['groupid'];
+				$sql_parts['where']['groupid'] = 'g.groupid='.zbx_dbstr($options['filter']['groupid']);
 
 			if(isset($options['filter']['name']))
 				$sql_parts['where']['name'] = 'g.name='.zbx_dbstr($options['filter']['name']);
@@ -623,7 +623,7 @@
 				break;
 			}
 
-			$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)){
 				$result = false;
 				break;
@@ -860,7 +860,7 @@
 			foreach($objectids as $hostid){
 				if(isset($linked[$groupid]) && 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 ($hostgroupid, ".zbx_dbstr($hostid).", ".zbx_dbstr($groupid).")");
 				if(!$result){
 					break 2;
 				}
@@ -1087,7 +1087,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 ($hostgroupid, ".zbx_dbstr($objectid).", ".zbx_dbstr($groupid).")");
 				if(!$result){
 					break 2;
 				}
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)
@@ -144,7 +144,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
@@ -468,12 +468,12 @@
 		$usrgrpid = $rights['usrgrpid'];
 
 		self::BeginTransaction(__METHOD__);
-		$result=DBexecute("DELETE FROM rights WHERE groupid=".$usrgrpid);
+		$result=DBexecute("DELETE FROM rights WHERE groupid=".zbx_dbstr($usrgrpid));
 
 		foreach($rights['rights'] as $right){
 			$id = get_dbid('rights', 'rightid');
 			$result = DBexecute('INSERT INTO rights (rightid, groupid, permission, id)'.
-				' VALUES ('.$id.','.$usrgrpid.','.$right['permission'].','.$right['id'].')');
+				' VALUES ('.$id.','.zbx_dbstr($usrgrpid).','.zbx_dbstr($right['permission']).','.zbx_dbstr($right['id']).')');
 			if(!$result) break;
 		}
 
@@ -512,18 +512,18 @@
 
 		self::BeginTransaction(__METHOD__);
 		foreach($rights['rights'] as $right){
-			$sql = 'SELECT rightid, permission FROM rights WHERE groupid='.$usrgrpid.' AND id='.$right['id'];
+			$sql = 'SELECT rightid, permission FROM rights WHERE groupid='.zbx_dbstr($usrgrpid).' AND id='.zbx_dbstr($right['id']);
 			$curr_perm = DBfetch(DBselect($sql));
 
 			if($curr_perm){
 				if($curr_perm['permission'] != $right['permission']){
-					$sql = 'UPDATE rights SET permission='.$right['permission'].' WHERE rightid='.$curr_perm['rightid'];
+					$sql = 'UPDATE rights SET permission='.zbx_dbstr($right['permission']).' WHERE rightid='.zbx_dbstr($curr_perm['rightid']);
 				}
 			}
 			else{
 				$id = get_dbid('rights', 'rightid');
 				$sql = 'INSERT INTO rights (rightid, groupid, permission, id)'.
-					' VALUES ('.$id.','.$usrgrpid.','.$right['permission'].','.$right['id'].')';
+					' VALUES ('.$id.','.zbx_dbstr($usrgrpid).','.zbx_dbstr($right['permission']).','.zbx_dbstr($right['id']).')';
 			}
 
 			$result = DBexecute($sql);
@@ -603,7 +603,7 @@
 			foreach($users as $unaum => $user){
 				$users_groups_id = get_dbid('users_groups', 'id');
 				$sql = 'INSERT INTO users_groups (id, usrgrpid, userid) '.
-						' VALUES ('.$users_groups_id.','.$usrgrp['usrgrpid'].','.$user['userid'].')';
+						' VALUES ('.$users_groups_id.','.zbx_dbstr($usrgrp['usrgrpid']).','.zbx_dbstr($user['userid']).')';
 				$result = DBexecute($sql);
 				if(!$result){
 					$errors[] = array('errno' => ZBX_API_ERROR_PARAMETERS, 'error' => 'Error adding user to group');
Index: frontends/php/api/classes/class.citem.php
===================================================================
--- frontends/php/api/classes/class.citem.php	(revision 38884)
+++ frontends/php/api/classes/class.citem.php	(working copy)
@@ -289,10 +289,10 @@
 			}
 
 			if(isset($options['filter']['hostid']))
-				$sql_parts['where']['hostid'] = 'i.hostid='.$options['filter']['hostid'];
+				$sql_parts['where']['hostid'] = 'i.hostid='.zbx_dbstr($options['filter']['hostid']);
 
 			if(isset($options['filter']['itemid']))
-				$sql_parts['where']['itemid'] = 'i.itemid='.$options['filter']['itemid'];
+				$sql_parts['where']['itemid'] = 'i.itemid='.zbx_dbstr($options['filter']['itemid']);
 				
 			if(isset($options['filter']['description']))
 				$sql_parts['where']['description'] = 'i.description='.zbx_dbstr($options['filter']['description']);
@@ -301,7 +301,7 @@
 				$sql_parts['where']['key_'] = 'i.key_='.zbx_dbstr($options['filter']['key_']);
 
 			if(isset($options['filter']['type']))
-				$sql_parts['where'][] = 'i.type='.$options['filter']['type'];
+				$sql_parts['where'][] = 'i.type='.zbx_dbstr($options['filter']['type']);
 
 			if(isset($options['filter']['snmp_community']))
 				$sql_parts['where'][] = 'i.snmp_community='.zbx_dbstr($options['filter']['snmp_community']);
@@ -310,7 +310,7 @@
 				$sql_parts['where'][] = 'i.snmp_oid='.zbx_dbstr($options['filter']['snmp_oid']);
 
 			if(isset($options['filter']['snmp_port']))
-				$sql_parts['where'][] = 'i.snmp_port='.$options['filter']['snmp_port'];
+				$sql_parts['where'][] = 'i.snmp_port='.zbx_dbstr($options['filter']['snmp_port']);
 
 			if(isset($options['filter']['value_type'])){
 				zbx_value2array($options['filter']['value_type']);
@@ -319,19 +319,19 @@
 			}
 
 			if(isset($options['filter']['data_type']))
-				$sql_parts['where'][] = 'i.data_type='.$options['filter']['data_type'];
+				$sql_parts['where'][] = 'i.data_type='.zbx_dbstr($options['filter']['data_type']);
 
 			if(isset($options['filter']['delay']))
-				$sql_parts['where'][] = 'i.delay='.$options['filter']['delay'];
+				$sql_parts['where'][] = 'i.delay='.zbx_dbstr($options['filter']['delay']);
 
 			if(isset($options['filter']['trends']))
-				$sql_parts['where'][] = 'i.trends='.$options['filter']['trends'];
+				$sql_parts['where'][] = 'i.trends='.zbx_dbstr($options['filter']['trends']);
 
 			if(isset($options['filter']['history']))
-				$sql_parts['where'][] = 'i.history='.$options['filter']['history'];
+				$sql_parts['where'][] = 'i.history='.zbx_dbstr($options['filter']['history']);
 
 			if(isset($options['filter']['status']))
-				$sql_parts['where'][] = 'i.status='.$options['filter']['status'];
+				$sql_parts['where'][] = 'i.status='.zbx_dbstr($options['filter']['status']);
 		}
 
 // group
Index: frontends/php/api/classes/class.cusermacro.php
===================================================================
--- frontends/php/api/classes/class.cusermacro.php	(revision 38884)
+++ frontends/php/api/classes/class.cusermacro.php	(working copy)
@@ -491,7 +491,7 @@
 		foreach($macros as $hostid => $mac_list){
 			$sql = 'SELECT hostmacroid '.
 					' FROM hostmacro '.
-					' WHERE hostid='.$hostid.
+					' WHERE hostid='.zbx_dbstr($hostid).
 					' AND '.DBcondition('macro', $mac_list, false, true);
 			$res = DBselect($sql);
 			while($macro = DBfetch($res)){
@@ -535,7 +535,7 @@
 				$hostmacroid = get_dbid('hostmacro', 'hostmacroid');
 
 				$sql = 'INSERT INTO hostmacro (hostmacroid, hostid, macro, value)
-					VALUES('.$hostmacroid.', '.$macro['hostid'].', '.zbx_dbstr($macro['macro']).', '.zbx_dbstr($macro['value']).')';
+					VALUES('.$hostmacroid.', '.zbx_dbstr($macro['hostid']).', '.zbx_dbstr($macro['macro']).', '.zbx_dbstr($macro['value']).')';
 				$result = DBExecute($sql);
 
 				if(!$result) break;
@@ -638,7 +638,7 @@
 
 			$sql = 'UPDATE hostmacro '.
 					' SET value='.zbx_dbstr($macro['value']).
-					' WHERE hostid='.$macro['hostid'].
+					' WHERE hostid='.zbx_dbstr($macro['hostid']).
 						' AND macro='.zbx_dbstr($macro['macro']);
 			$result = DBExecute($sql);
 
@@ -835,7 +835,7 @@
 
 		$sql = 'SELECT globalmacroid '.
 				' FROM globalmacro '.
-				' WHERE globalmacroid='.$macro_data['globalmacroid'];
+				' WHERE globalmacroid='.zbx_dbstr($macro_data['globalmacroid']);
 		$res = DBselect($sql);
 		while($macro = DBfetch($res)){
 			$globalmacroids[$macro[globalmacroid]] = $macro[globalmacroid];
@@ -867,7 +867,7 @@
 		$sql = 'SELECT hostmacroid '.
 				' FROM hostmacro '.
 				' WHERE macro='.zbx_dbstr($macro_data['macro']).
-					' AND hostid='.$macro_data['hostid'].
+					' AND hostid='.zbx_dbstr($macro_data['hostid']).
 					' AND '.DBin_node('hostmacroid', false);
 		$res = DBselect($sql);
 		if($macroid = DBfetch($res))
@@ -928,7 +928,7 @@
 								if(($link['macro'] == $macro['macro']) && ($link['hostid'] == $hostid)) continue 2;
 							}
 
-							$values = array(get_dbid('hostmacro', 'hostmacroid'), $hostid, zbx_dbstr($macro['macro']),
+							$values = array(get_dbid('hostmacro', 'hostmacroid'), zbx_dbstr($hostid), zbx_dbstr($macro['macro']),
 								zbx_dbstr($macro['value']));
 							$sql = 'INSERT INTO hostmacro (hostmacroid, hostid, macro, value) VALUES ('. implode(', ', $values) .')';
 
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)
@@ -204,7 +204,7 @@
 
 // type
 		if(!is_null($options['type'] )){
-			$sql_parts['where'][] = 'g.type='.$options['type'];
+			$sql_parts['where'][] = 'g.type='.zbx_dbstr($options['type']);
 		}
 
 // templated
@@ -267,7 +267,7 @@
 				$sql_parts['where']['name'] = 'g.name='.zbx_dbstr($options['filter']['name']);
 
 			if(isset($options['filter']['templateid']))
-				$sql_parts['where']['templateid'] = 'g.templateid='.$options['filter']['templateid'];
+				$sql_parts['where']['templateid'] = 'g.templateid='.zbx_dbstr($options['filter']['templateid']);
 
 			if(isset($options['filter']['host']) || isset($options['filter']['hostid'])){
 				$sql_parts['from']['gi'] = 'graphs_items gi';
@@ -282,7 +282,7 @@
 				}
 
 				if(isset($options['filter']['hostid']))
-					$sql_parts['where']['hostid'] = 'i.hostid='.$options['filter']['hostid'];
+					$sql_parts['where']['hostid'] = 'i.hostid='.zbx_dbstr($options['filter']['hostid']);
 			}
 		}
 
@@ -751,23 +751,23 @@
 			'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).')';
 		DBexecute($sql) or self::exception(ZBX_API_ERROR_PARAMETERS, 'DBerror');			
 	
@@ -776,14 +776,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');
@@ -794,7 +794,7 @@
 	
 	protected static function updateReal($graph){
 		$values = array(
-			'name' => zbx_dbstr($graph['name'])
+			'name' => $graph['name']
 		);
 		if(isset($graph['width'])) $values['width'] = $graph['width'];
 		if(isset($graph['height'])) $values['height'] = $graph['height'];
@@ -815,29 +815,29 @@
 		
 		$q = '';
 		foreach($values as $field => $value){
-			$q .= $field.'='.$value.', ';
+			$q .= $field.'='.zbx_dbstr($value).', ';
 		}
 		$q = rtrim($q, ', ');
-		$sql = 'UPDATE graphs SET '.$q.' WHERE graphid='.$graph['graphid'];
+		$sql = 'UPDATE graphs SET '.$q.' WHERE graphid='.zbx_dbstr($graph['graphid']);
 		DBexecute($sql) or self::exception(ZBX_API_ERROR_PARAMETERS, 'DBerror');			
 	
 	
-		DBexecute('DELETE FROM graphs_items WHERE graphid='.$graph['graphid'])
+		DBexecute('DELETE FROM graphs_items WHERE graphid='.zbx_dbstr($graph['graphid']))
 			or self::exception(ZBX_API_ERROR_PARAMETERS, 'DBerror');
 		
 		foreach($graph['gitems'] as $gitem){
 			$values = array(
 				'gitemid' => get_dbid('graphs_items', 'gitemid'),
-				'graphid' => $graph['graphid']
+				'graphid' => zbx_dbstr($graph['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');
@@ -1127,7 +1127,7 @@
 		if($host["status"] == HOST_STATUS_TEMPLATE ){
 			$sql = 'SELECT DISTINCT count(i.hostid) as count
 					FROM items i
-					WHERE i.hostid<>'.$host['hostid'].
+					WHERE i.hostid<>'.zbx_dbstr($host['hostid']).
 						' AND '.DBcondition('i.itemid', $itemids);
 
 			$host_count = DBfetch(DBselect($sql));
@@ -1219,7 +1219,7 @@
 
 		$sql = 'DELETE
 				FROM graphs_items
-				WHERE graphid='.$graphid.
+				WHERE graphid='.zbx_dbstr($graphid).
 					' AND '.DBcondition('itemid', $gitems);
 		$result = DBselect($sql);
 
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)
@@ -251,7 +251,7 @@
 				$sql_parts['where']['name'] = 'a.name='.zbx_dbstr($options['filter']['name']);
 
 			if(isset($options['filter']['hostid']))
-				$sql_parts['where']['hostid'] = 'a.hostid='.$options['filter']['hostid'];
+				$sql_parts['where']['hostid'] = 'a.hostid='.zbx_dbstr($options['filter']['hostid']);
 		}
 
 // order
@@ -676,7 +676,7 @@
 				if(isset($linked[$applicationid]) && isset($linked[$applicationid][$itemid])) continue;
 
 				$itemappid = get_dbid('items_applications', 'itemappid');
-				$result = DBexecute("INSERT INTO items_applications (itemappid, itemid, applicationid) VALUES ($itemappid, $itemid, $applicationid)");
+				$result = DBexecute("INSERT INTO items_applications (itemappid, itemid, applicationid) VALUES ($itemappid, ".zbx_dbstr($itemid).", ".zbx_dbstr($applicationid).")");
 				if(!$result){
 					break 2;
 				}
@@ -686,13 +686,13 @@
 		if($result){
 			$child_applications = array();
 			foreach($itemids as $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));
 
 				if($child = DBfetch($db_childs)){
 					$sql = 'SELECT a1.applicationid '.
 							' FROM applications a1, applications a2 '.
 							' WHERE a1.name=a2.name '.
-								' AND a1.hostid='.$child['hostid'].
+								' AND a1.hostid='.zbx_dbstr($child['hostid']).
 								' AND '.DBcondition('a2.applicationid', $applicationids);
 					$db_apps = DBselect($sql);
 					while($app = DBfetch($db_apps)){
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)
@@ -252,7 +252,7 @@
 
 // status
 		if(!is_null($options['status'])){
-			$sql_parts['where'][] = 't.status='.$options['status'];
+			$sql_parts['where'][] = 't.status='.zbx_dbstr($options['status']);
 		}
 
 // monitored
@@ -432,7 +432,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']);
 		}
 
 // countOutput
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)
@@ -342,7 +342,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)
@@ -266,27 +266,27 @@
 
 // status
 		if(!is_null($options['status'])){
-			$sql_parts['where'][] = 'a.status='.$options['status'];
+			$sql_parts['where'][] = 'a.status='.zbx_dbstr($options['status']);
 		}
 
 // sendto
 		if(!is_null($options['sendto'])){
-			$sql_parts['where'][] = 'a.sendto='.$options['sendto'];
+			$sql_parts['where'][] = 'a.sendto='.zbx_dbstr($options['sendto']);
 		}
 
 // alerttype
 		if(!is_null($options['alerttype'])){
-			$sql_parts['where'][] = 'a.alerttype='.$options['alerttype'];
+			$sql_parts['where'][] = 'a.alerttype='.zbx_dbstr($options['alerttype']);
 		}
 
 // 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
@@ -514,10 +514,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/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/reports.inc.php
===================================================================
--- frontends/php/include/reports.inc.php	(revision 38884)
+++ frontends/php/include/reports.inc.php	(working copy)
@@ -64,10 +64,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 '.
@@ -91,7 +91,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)
@@ -247,9 +247,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
 					,
 
@@ -257,9 +257,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
 					);
 			}
@@ -270,9 +270,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
 					,
 
@@ -280,9 +280,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,11 +451,11 @@
 						" AND f.function IN ('last','min','avg','max') ".
 						' AND tr.status='.TRIGGER_STATUS_ENABLED.
 						' AND i.itemid=f.itemid '.
-						' 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)){
-				$db_fnc_cnt = DBselect('SELECT count(*) as cnt FROM functions f WHERE f.triggerid='.$trigger['triggerid']);
+				$db_fnc_cnt = DBselect('SELECT count(*) as cnt FROM functions f WHERE f.triggerid='.zbx_dbstr($trigger['triggerid']));
 				$fnc_cnt = DBfetch($db_fnc_cnt);
 
 				if($fnc_cnt['cnt'] != 1) continue;
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)
@@ -190,9 +190,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'
 					,
 
@@ -201,9 +201,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'
 					);
 			}
@@ -215,9 +215,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'
 					,
 
@@ -226,9 +226,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/hosts.inc.php
===================================================================
--- frontends/php/include/hosts.inc.php	(revision 38884)
+++ frontends/php/include/hosts.inc.php	(working copy)
@@ -49,7 +49,7 @@
 
 			return false;
 		}
-		$result = DBexecute('DELETE FROM hosts_groups WHERE groupid='.$groupid);
+		$result = DBexecute('DELETE FROM hosts_groups WHERE groupid='.zbx_dbstr($groupid));
 		$hosts = zbx_toObject($hosts, 'hostid');
 
 		$options = array(
@@ -79,7 +79,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;
 	}
@@ -188,7 +188,7 @@
 				' WHERE h.host='.zbx_dbstr($host).
 					' AND '.DBin_node('h.hostid', get_current_nodeid(false)).
 					' AND status IN ('.HOST_STATUS_MONITORED.','.HOST_STATUS_NOT_MONITORED.','.HOST_STATUS_TEMPLATE.')'.
-					(isset($hostid)?' AND h.hostid<>'.$hostid:'');
+					(isset($hostid)?' AND h.hostid<>'.zbx_dbstr($hostid):'');
 		if(DBfetch(DBselect($sql))){
 			error(S_HOST.SPACE.'"'.$host.'"'.SPACE.S_ALREADY_EXISTS_SMALL);
 			return false;
@@ -199,8 +199,8 @@
 			$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.','.$proxy_hostid.','.zbx_dbstr($host).','.$port.','.$status.','.$useip.','.zbx_dbstr($dns).','.zbx_dbstr($ip).',0,'
-					.HOST_AVAILABLE_UNKNOWN.','.($useipmi === 'yes' ? 1 : 0).','.$ipmi_port.','.$ipmi_authtype.','.$ipmi_privilege.','.zbx_dbstr($ipmi_username).','
+				' VALUES ('.$hostid.','.zbx_dbstr($proxy_hostid).','.zbx_dbstr($host).','.zbx_dbstr($port).','.zbx_dbstr($status).','.zbx_dbstr($useip).','.zbx_dbstr($dns).','.zbx_dbstr($ip).',0,'
+					.HOST_AVAILABLE_UNKNOWN.','.($useipmi === 'yes' ? 1 : 0).','.zbx_dbstr($ipmi_port).','.zbx_dbstr($ipmi_authtype).','.zbx_dbstr($ipmi_privilege).','.zbx_dbstr($ipmi_username).','
 					.zbx_dbstr($ipmi_password).','.zbx_dbstr($ipmi_ip).')');
 			if($result){
 				add_audit_ext(AUDIT_ACTION_ADD, AUDIT_RESOURCE_HOST, $hostid, $host, 'hosts', NULL, NULL);
@@ -213,21 +213,21 @@
 			}
 
 			$host_old = get_host_by_hostid($hostid);
-			$result = DBexecute('UPDATE hosts SET proxy_hostid='.$proxy_hostid.
+			$result = DBexecute('UPDATE hosts SET proxy_hostid='.zbx_dbstr($proxy_hostid).
 							',host='.zbx_dbstr($host).
-							',port='.$port.
-							',status='.$status.
-							',useip='.$useip.
+							',port='.zbx_dbstr($port).
+							',status='.zbx_dbstr($status).
+							',useip='.zbx_dbstr($useip).
 							',dns='.zbx_dbstr($dns).
 							',ip='.zbx_dbstr($ip).
 							',useipmi='.($useipmi == 'yes' ? 1 : 0).
-							',ipmi_port='.$ipmi_port.
-							',ipmi_authtype='.$ipmi_authtype.
-							',ipmi_privilege='.$ipmi_privilege.
+							',ipmi_port='.zbx_dbstr($ipmi_port).
+							',ipmi_authtype='.zbx_dbstr($ipmi_authtype).
+							',ipmi_privilege='.zbx_dbstr($ipmi_privilege).
 							',ipmi_username='.zbx_dbstr($ipmi_username).
 							',ipmi_password='.zbx_dbstr($ipmi_password).
 							',ipmi_ip='.zbx_dbstr($ipmi_ip).
-				' WHERE hostid='.$hostid);
+				' WHERE hostid='.zbx_dbstr($hostid));
 
 			if($result){
 				$host_new = get_host_by_hostid($hostid);
@@ -238,7 +238,7 @@
 
 		foreach($templates as $id => $name){
 			$hosttemplateid = get_dbid('hosts_templates', 'hosttemplateid');
-			if(!$result = DBexecute('INSERT INTO hosts_templates VALUES ('.$hosttemplateid.','.$hostid.','.$id.')'))
+			if(!$result = DBexecute('INSERT INTO hosts_templates VALUES ('.$hosttemplateid.','.zbx_dbstr($hostid).','.zbx_dbstr($id).')'))
 				break;
 		}
 
@@ -323,7 +323,7 @@
 				if(isset($linked[$groupid]) && 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 ('.$hostgroupid.','.zbx_dbstr($hostid).','.zbx_dbstr($groupid).')');
 				if(!$result){
 					return false;
 				}
@@ -435,7 +435,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;
 	}
 
@@ -517,7 +517,7 @@
 		}
 
 		foreach($hostids as $id => $hostid){
-			$sql='DELETE FROM hosts_groups WHERE hostid='.$hostid.' AND '.DBcondition('groupid', $groupids);
+			$sql='DELETE FROM hosts_groups WHERE hostid='.zbx_dbstr($hostid).' AND '.DBcondition('groupid', $groupids);
 			DBexecute($sql);
 		}
 
@@ -642,7 +642,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)
 				add_audit_ext(AUDIT_ACTION_DELETE, AUDIT_RESOURCE_HOST, $id, $host_old['host'], 'hosts', NULL, NULL);
 			else
@@ -734,7 +734,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
@@ -745,7 +745,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;
@@ -759,7 +759,7 @@
 
 		$result=DBselect('SELECT DISTINCT hg.groupid '.
 						' FROM hosts_groups hg '.
-						' WHERE hg.hostid='.$hostid);
+						' WHERE hg.hostid='.zbx_dbstr($hostid));
 		while($row=DBfetch($result)){
 			$groupids[$row['groupid']] = $row['groupid'];
 		}
@@ -779,7 +779,7 @@
 		else
 			$result = DBselect('SELECT * FROM hosts WHERE status IN ('.HOST_STATUS_PROXY.')'.
 					' 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);
@@ -797,7 +797,7 @@
 			return $proxyid;
 		}
 		else
-			return DBexecute('update hosts set host='.zbx_dbstr($name).' where hostid='.$proxyid);
+			return DBexecute('update hosts set host='.zbx_dbstr($name).' where hostid='.zbx_dbstr($proxyid));
 	}
 
 	function delete_proxy($proxyids){
@@ -832,10 +832,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));
 		}
 	}
 
@@ -890,7 +890,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){
@@ -928,7 +928,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;
@@ -971,7 +971,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)){
@@ -1511,7 +1511,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;
 				}
@@ -1640,9 +1640,9 @@
 		$sql = 'SELECT applicationid
 			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));
 
@@ -1664,15 +1664,15 @@
 			$applicationid_new = get_dbid('applications', 'applicationid');
 
 			$sql = 'INSERT INTO applications (applicationid, name, hostid, templateid) '.
-				" VALUES ($applicationid_new, ".zbx_dbstr($name).", $hostid, $templateid)";
+				" VALUES ($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_UPDATED_APPLICATION.SPACE.$host['host'].':'.$old_app['name']);
 		}
@@ -1805,7 +1805,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)
 		{
@@ -1818,7 +1818,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){
@@ -1830,7 +1830,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)
@@ -1842,11 +1842,11 @@
 	}
 
 	function get_items_by_applicationid($applicationid){
-		return DBselect("select i.* from items i,items_applications ia where i.itemid=ia.itemid and ia.applicationid=$applicationid");
+		return DBselect("select i.* from items i,items_applications ia where i.itemid=ia.itemid and ia.applicationid=".zbx_dbstr($applicationid));
 	}
 
 	function get_applications_by_hostid($hostid){
-		return DBselect('select * from applications where hostid='.$hostid);
+		return DBselect('select * from applications where hostid='.zbx_dbstr($hostid));
 	}
 
 	/*
@@ -2006,7 +2006,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;
@@ -2047,7 +2047,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)
@@ -75,23 +75,23 @@
 
 		$sql = 'UPDATE users SET '.
 					' url='.zbx_dbstr($url).','.
-					' autologin='.$autologin.','.
-					' autologout='.$autologout.','.
+					' autologin='.zbx_dbstr($autologin).','.
+					' autologout='.zbx_dbstr($autologout).','.
 					' lang='.zbx_dbstr($lang).','.
 					' theme='.zbx_dbstr($theme).','.
 					(isset($passwd)?(' passwd='.zbx_dbstr(md5($passwd)).',') : '').
-					' refresh='.$refresh.
-				' WHERE userid='.$userid;
+					' refresh='.zbx_dbstr($refresh).
+				' WHERE userid='.zbx_dbstr($userid);
 
 		$result = DBexecute($sql);
 
-		$result = DBexecute('DELEET FROM media WHERE userid='.$userid);
+		$result = DBexecute('DELEET FROM media WHERE userid='.zbx_dbstr($userid));
 			foreach($user_medias as $mediaid => $media_data){
 				$mediaid = get_dbid("media","mediaid");
 
 				$sql = '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']).')';
 
 				$result = DBexecute($sql);
@@ -122,11 +122,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);
@@ -137,7 +137,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);
@@ -203,11 +203,11 @@
 			if(!$result)	return	$result;
 		}
 
-		$result=DBexecute("delete from rights where groupid=".$usrgrpid);
+		$result=DBexecute("delete from rights where groupid=".zbx_dbstr($usrgrpid));
 		foreach($rights as $right){
 			$id = get_dbid('rights','rightid');
 			$result=DBexecute('insert into rights (rightid,groupid,permission,id)'.
-				' values ('.$id.','.$usrgrpid.','.$right['permission'].','.$right['id'].')');
+				' values ('.$id.','.$usrgrpid.','.zbx_dbstr($right['permission']).','.zbx_dbstr($right['id']).')');
 
 			if(!$result)	return	$result;
 		}
@@ -221,14 +221,14 @@
 		$sql = 'SELECT * '.
 				' FROM usrgrp '.
 				' WHERE name='.zbx_dbstr($name).
-					' AND usrgrpid<>'.$usrgrpid.
+					' AND usrgrpid<>'.zbx_dbstr($usrgrpid).
 					' AND '.DBin_node('usrgrpid', false);
 		if(DBfetch(DBselect($sql))){
 			error(S_GROUP.SPACE.$name.SPACE.S_ALREADY_EXISTS_SMALL);
 			return 0;
 		}
 
-		$result=DBexecute('UPDATE usrgrp SET name='.zbx_dbstr($name).' WHERE usrgrpid='.$usrgrpid);
+		$result=DBexecute('UPDATE usrgrp SET name='.zbx_dbstr($name).' WHERE usrgrpid='.zbx_dbstr($usrgrpid));
 		if(!$result) return	$result;
 
 // must come before adding user to group
@@ -244,7 +244,7 @@
 			$grant = !uint_in_array($USER_DETAILS['userid'],$users);
 		}
 		if($grant){
-			$result = DBexecute('DELETE FROM users_groups WHERE usrgrpid='.$usrgrpid);
+			$result = DBexecute('DELETE FROM users_groups WHERE usrgrpid='.zbx_dbstr($usrgrpid));
 			foreach($users as $userid => $name){
 				$result = add_user_to_group($userid,$usrgrpid);
 				if(!$result)	return	$result;
@@ -255,11 +255,11 @@
 			return false;
 		}
 
-		$result=DBexecute('DELETE FROM rights WHERE groupid='.$usrgrpid);
+		$result=DBexecute('DELETE FROM rights WHERE groupid='.zbx_dbstr($usrgrpid));
 		foreach($rights as $right){
 			$id = get_dbid('rights','rightid');
 			$result = DBexecute('INSERT INTO rights (rightid,groupid,permission,id)'.
-				' VALUES ('.$id.','.$usrgrpid.','.$right['permission'].','.$right['id'].')');
+				' VALUES ('.$id.','.zbx_dbstr($usrgrpid).','.zbx_dbstr($right['permission']).','.zbx_dbstr($right['id']).')');
 
 			if(!$result)	return	$result;
 		}
@@ -291,7 +291,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);
 
@@ -307,7 +307,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);
 
@@ -317,14 +317,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/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;
 }
@@ -77,7 +77,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))){
@@ -121,7 +121,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));
 
@@ -135,7 +135,7 @@
 function get_user_api_access($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.api_access = '.GROUP_API_ACCESS_ENABLED;
 	if($res = DBfetch(DBselect($sql,1))){
@@ -147,7 +147,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))){
@@ -279,7 +279,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 '.
@@ -363,7 +363,7 @@
 	$sql = 'SELECT n.nodeid as nodeid,n.name as node_name,hg.groupid,hg.name,min(r.permission) as permission,g.userid'.
 		' FROM groups hg '.
 			' LEFT JOIN rights r ON r.id=hg.groupid '.
-			' LEFT JOIN users_groups g ON r.groupid=g.usrgrpid AND g.userid='.$userid.
+			' LEFT JOIN users_groups g ON r.groupid=g.usrgrpid AND g.userid='.zbx_dbstr($userid).
 			' LEFT JOIN nodes n ON '.DBid2nodeid('hg.groupid').'=n.nodeid '.
 		$where.
 		' GROUP BY n.nodeid, n.name, hg.groupid, hg.name, g.userid, g.userid '.
@@ -465,7 +465,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){
@@ -692,7 +692,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/config.inc.php
===================================================================
--- frontends/php/include/config.inc.php	(revision 38884)
+++ frontends/php/include/config.inc.php	(working copy)
@@ -1028,13 +1028,13 @@
 	}
 /*************** VALUE MAPPING ******************/
 	function add_mapping_to_valuemap($valuemapid, $mappings){
-		DBexecute("delete FROM mappings WHERE valuemapid=$valuemapid");
+		DBexecute("delete FROM mappings WHERE valuemapid=".zbx_dbstr($valuemapid));
 
 		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"]).",".
+				" values (".$mappingid.",".zbx_dbstr($valuemapid).",".zbx_dbstr($map["value"]).",".
 				zbx_dbstr($map["newvalue"]).")");
 
 			if(!$result)
@@ -1066,7 +1066,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;
@@ -1079,8 +1079,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;
 	}
 
Index: frontends/php/include/audit.inc.php
===================================================================
--- frontends/php/include/audit.inc.php	(revision 38884)
+++ frontends/php/include/audit.inc.php	(working copy)
@@ -73,7 +73,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;
@@ -107,7 +107,7 @@
 		$ip = (isset($_SERVER['HTTP_X_FORWARDED_FOR']) && !empty($_SERVER['HTTP_X_FORWARDED_FOR']))?$_SERVER['HTTP_X_FORWARDED_FOR']:$_SERVER['REMOTE_ADDR'];
 		$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)
@@ -144,12 +144,12 @@
 
 	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,
@@ -158,9 +158,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;
@@ -176,7 +176,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;
@@ -188,8 +188,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;
 		}
@@ -204,8 +204,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))
 		{
@@ -220,8 +220,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));
 		}
 
 		if($result && isset($dchecks_deleted) && !empty($dchecks_deleted))
@@ -269,7 +269,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))
@@ -285,12 +285,12 @@
 // 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'.
@@ -298,13 +298,13 @@
 		}
 
 		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);
 		}
 
@@ -288,19 +288,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 */
 		}
 
@@ -314,16 +314,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);
 
@@ -335,8 +335,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);
 		}
@@ -346,7 +346,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/blocks.inc.php
===================================================================
--- frontends/php/include/blocks.inc.php	(revision 38884)
+++ frontends/php/include/blocks.inc.php	(working copy)
@@ -783,7 +783,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);
@@ -876,7 +876,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)
@@ -648,7 +648,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/profiles.inc.php
===================================================================
--- frontends/php/include/profiles.inc.php	(revision 38884)
+++ frontends/php/include/profiles.inc.php	(working copy)
@@ -132,9 +132,9 @@
 			'profileid' => get_dbid('profiles', 'profileid'),
 			'userid' => $USER_DETAILS['userid'],
 			'idx' => zbx_dbstr($idx),
-			$value_type => ($value_type == 'value_str') ? zbx_dbstr($value) : $value,
-			'type' => $type,
-			'idx2' => $idx2
+			$value_type => zbx_dbstr($value),
+			'type' => zbx_dbstr($type),
+			'idx2' => zbx_dbstr($idx2)
 		);
 
 		$sql = 'INSERT INTO profiles ('.implode(', ', array_keys($values)).') VALUES ('.implode(', ', $values).')';
@@ -152,11 +152,10 @@
 		if($idx2 > 0) $sql_cond.= ' AND idx2='.$idx2.' AND '.DBin_node('idx2', false);
 		
 		$value_type = self::getFieldByType($type);
-		$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;
@@ -227,7 +226,7 @@
 		}
 	}
 	if(isset($configs['alert_usrgrpid']) && !is_null($configs['alert_usrgrpid'])){
-		if(($configs['alert_usrgrpid'] != 0) && !DBfetch(DBselect('select usrgrpid from usrgrp where usrgrpid='.$configs['alert_usrgrpid']))){
+		if(($configs['alert_usrgrpid'] != 0) && !DBfetch(DBselect('select usrgrpid from usrgrp where usrgrpid='.zbx_dbstr($configs['alert_usrgrpid'])))){
 			error(S_INCORRECT_GROUP);;
 			return NULL;
 		}
@@ -295,7 +294,7 @@
 	}
 
 	$sql = 'SELECT title5, url5
-			FROM user_history WHERE userid='.$userid;
+			FROM user_history WHERE userid='.zbx_dbstr($userid);
 	$history5 = DBfetch(DBSelect($sql));
 
 	if($history5 && ($history5['title5'] == $title)){ //title is same
@@ -373,7 +372,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);
@@ -393,7 +392,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/services.inc.php
===================================================================
--- frontends/php/include/services.inc.php	(revision 38884)
+++ frontends/php/include/services.inc.php	(working copy)
@@ -28,8 +28,6 @@
 			}
 		}
 
-		if(is_null($triggerid) || $triggerid==0) $triggerid = 'NULL';
-
 		$serviceid=get_dbid("services","serviceid");
 
 		remove_service_links($serviceid); //removes all links with current serviceid
@@ -45,19 +43,26 @@
 			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;
 
 		update_services_status_all(); // updating status to all services by the dependency
 
-		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.','.$serviceid.','.zbx_dbstr($val['type']).','.zbx_dbstr($val['from']).','.zbx_dbstr($val['to']).','.zbx_dbstr($val['note']).')');
 
 			if(!$result)
 			{
@@ -86,21 +91,26 @@
 
 		if(!$result) return FALSE;
 
-		if(is_null($triggerid) || $triggerid==0) $triggerid = 'NULL';
+		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));
 
 		update_services_status_all(); // updating status to all services by the dependency
 
-		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');
 			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;
@@ -109,7 +119,7 @@
 	function	add_host_to_services($hostid, $serviceid){
 		$result = DBselect('SELECT distinct h.host,t.triggerid,t.description,t.expression '.
 							' FROM triggers t,hosts h,items i,functions f '.
-							' WHERE h.hostid='.$hostid.
+							' WHERE h.hostid='.zbx_dbstr($hostid).
 								' AND h.hostid=i.hostid '.
 								' AND i.itemid=f.itemid '.
 								' AND f.triggerid=t.triggerid '.
@@ -124,7 +134,7 @@
 	}
 
 	function	is_service_hardlinked($serviceid){
-		$row = DBfetch(DBselect("SELECT count(*) as cnt FROM services_links WHERE servicedownid=".$serviceid." and soft=0"));
+		$row = DBfetch(DBselect("SELECT count(*) as cnt FROM services_links WHERE servicedownid=".zbx_dbstr($serviceid)." and soft=0"));
 		if($row["cnt"]>0)
 		{
 			return	TRUE;
@@ -156,7 +166,7 @@
 
 			$sql = '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;
 			$result = DBselect($sql);
@@ -175,16 +185,16 @@
 	 *                                                                            *
 	 ******************************************************************************/
 	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;
 
 		update_services_status_all();
@@ -209,7 +219,7 @@
 		if($serviceid != 0){
 			$sql='UPDATE services '.
 					' SET triggerid = null '.
-					' WHERE serviceid = '.$serviceid;
+					' WHERE serviceid = '.zbx_dbstr($serviceid);
 			DBexecute($sql);
 		return;
 		}
@@ -224,7 +234,7 @@
 		while($rows = DBfetch($res)){
 			$sql='UPDATE services '.
 					' SET triggerid = null '.
-					' WHERE serviceid = '.$rows['serviceid'];
+					' WHERE serviceid = '.zbx_dbstr($rows['serviceid']);
 			DBexecute($sql);
 		}
 	}
@@ -243,7 +253,7 @@
 
 		}
 
-		$result=DBselect("SELECT serviceupid FROM services_links WHERE servicedownid=$serviceid2 and soft=0");
+		$result=DBselect("SELECT serviceupid FROM services_links WHERE servicedownid=".zbx_dbstr($serviceid2)." and soft=0");
 		while($row=DBfetch($result)){
 			if(does_service_depend_on_the_service($serviceid,$row["serviceupid"]) == TRUE){
 				return	TRUE;
@@ -253,7 +263,7 @@
 	}
 
 	function service_has_parent($serviceid){
-		$row = DBfetch(DBselect('SELECT linkid FROM services_links WHERE servicedownid='.$serviceid));
+		$row = DBfetch(DBselect('SELECT linkid FROM services_links WHERE servicedownid='.zbx_dbstr($serviceid)));
 		if($row && !zbx_empty($row['linkid'])){
 			return	TRUE;
 		}
@@ -262,7 +272,7 @@
 
 // Seems not used ant more!
 	function service_has_no_this_parent($parentid,$serviceid){
-		$row = DBfetch(DBselect('SELECT linkid FROM services_links WHERE serviceupid='.$parentid.' AND servicedownid='.$serviceid));
+		$row = DBfetch(DBselect('SELECT linkid FROM services_links WHERE serviceupid='.zbx_dbstr($parentid).' AND servicedownid='.zbx_dbstr($serviceid)));
 		if($row && !zbx_empty($row['linkid'])){
 			return	FALSE;
 		}
@@ -282,7 +292,7 @@
 
 		$linkid=get_dbid("services_links","linkid");
 
-		$sql="INSERT INTO services_links (linkid,servicedownid,serviceupid,soft) values ($linkid,$servicedownid,$serviceupid,$softlink)";
+		$sql="INSERT INTO services_links (linkid,servicedownid,serviceupid,soft) values ($linkid,".zbx_dbstr($servicedownid).",".zbx_dbstr($serviceupid).",".zbx_dbstr($softlink).")";
 		$result=DBexecute($sql);
 
 		if(!$result)
@@ -301,27 +311,27 @@
 			return	false;
 		}
 
-		$sql="UPDATE services_links SET servicedownid=$servicedownid, serviceupid=$serviceupid, soft=$softlink WHERE linkid=$linkid";
+		$sql="UPDATE services_links SET servicedownid=".zbx_dbstr($servicedownid).", serviceupid=".zbx_dbstr($serviceupid).", soft=".zbx_dbstr($softlink)." WHERE linkid=".zbx_dbstr($linkid);
 		return	dbexecute($sql);
 	}
 
 	function remove_service_links($serviceid){
 		$query='DELETE
 				FROM services_links
-				WHERE serviceupid='.$serviceid.'
-					OR  (servicedownid='.$serviceid.'
+				WHERE serviceupid='.zbx_dbstr($serviceid).'
+					OR  (servicedownid='.zbx_dbstr($serviceid).'
 					AND soft<>1)';
 		DBExecute($query);
 	}
 
 	function get_last_service_value($serviceid,$clock){
-	       	$sql="SELECT count(*) as cnt,max(clock) as maxx FROM service_alarms WHERE serviceid=$serviceid and clock<=$clock";
+	       	$sql="SELECT count(*) as cnt,max(clock) as maxx FROM service_alarms WHERE serviceid=".zbx_dbstr($serviceid)." and clock<=".zbx_dbstr($clock);
 //		echo " $sql<br>";
 
 	        $result=DBselect($sql);
 		$row=DBfetch($result);
 		if($row["cnt"]>0){
-	       		$sql="SELECT value FROM service_alarms WHERE serviceid=$serviceid and clock=".$row["maxx"];
+	       		$sql="SELECT value FROM service_alarms WHERE serviceid=".zbx_dbstr($serviceid)." and clock=".zbx_dbstr($row["maxx"]);
 		        $result2=DBselect($sql);
 // Assuring that we get very latest service value. There could be several with the same timestamp
 //			$value=DBget_field($result2,0,0);
@@ -408,9 +418,9 @@
 /* sort by time stamp */
 		$sql = 'SELECT sa.servicealarmid, sa.clock, sa.value '.
 				' FROM service_alarms sa '.
-				' WHERE sa.serviceid='.$serviceid.
-					' AND sa.clock>='.$period_start.
-					' AND sa.clock<='.$period_end.
+				' WHERE sa.serviceid='.zbx_dbstr($serviceid).
+					' AND sa.clock>='.zbx_dbstr($period_start).
+					' AND sa.clock<='.zbx_dbstr($period_end).
 				' ORDER BY sa.clock asc, sa.servicealarmid asc';
 		$service_alarms = DBselect($sql);
 		while($db_alarm_row = DBfetch($service_alarms)){
@@ -421,7 +431,7 @@
 		$sql = '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);
 		$service_times = DBselect($sql);
 		if($db_time_row = DBfetch($service_times)){
 // if exist any uptime - unmarked time is downtime
@@ -440,7 +450,7 @@
 		$sql = 'SELECT ts_from,ts_to '.
 				' FROM services_times '.
 				' WHERE type='.SERVICE_TIME_TYPE_DOWNTIME.
-					' AND serviceid='.$serviceid;
+					' AND serviceid='.zbx_dbstr($serviceid);
 		$service_times = DBselect($sql);
 		while($db_time_row = DBfetch($service_times)){
 			expand_periodical_service_times($data,$period_start, $period_end,$db_time_row['ts_from'], $db_time_row['ts_to'],'dt');
@@ -450,7 +460,7 @@
 		$sql = 'SELECT ts_from,ts_to '.
 				' FROM services_times '.
 				' WHERE type='.SERVICE_TIME_TYPE_ONETIME_DOWNTIME.
-					' AND serviceid='.$serviceid;
+					' AND serviceid='.zbx_dbstr($serviceid);
 		$service_times = DBselect($sql);
 		while($db_time_row = DBfetch($service_times)){
 
@@ -587,13 +597,13 @@
 
 	function get_num_of_service_childs($serviceid){
 		$row = DBfetch(DBselect("SELECT count(distinct servicedownid) as cnt FROM services_links ".
-					" WHERE serviceupid=".$serviceid));
+					" WHERE serviceupid=".zbx_dbstr($serviceid)));
 	return	$row["cnt"];
 	}
 
 	function	get_service_by_serviceid($serviceid)
 	{
-		$res = DBfetch(DBselect("SELECT * FROM services WHERE serviceid=".$serviceid));
+		$res = DBfetch(DBselect("SELECT * FROM services WHERE serviceid=".zbx_dbstr($serviceid)));
 		if(!$res)
 		{
 			error(S_NO_SERVICE_WITH." serviceid=[".$serviceid."]");
@@ -603,7 +613,7 @@
 	}
 
 	function	get_services_links_by_linkid($linkid){
-		$result=DBselect("SELECT * FROM services_links WHERE linkid=$linkid");
+		$result=DBselect("SELECT * FROM services_links WHERE linkid=".zbx_dbstr($linkid));
 		$res = DBfetch($result);
 		if(!$res){
 			error(S_NO_SERVICE_LINKAGE_WITH." linkid=[$linkid]");
@@ -630,7 +640,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');
 
 		$res =  DBSelect($query);
 		while($row = DBFetch($res)){
@@ -741,7 +751,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($rows=DBfetch($result)){
@@ -756,7 +766,7 @@
 			$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));
 		}
 		else{
 			error(S_UNKNOWN_CALC_ALGORITHM_OF_SERVICE_STATUS.SPACE.'['.$algorithm.']');
@@ -764,7 +774,7 @@
 		}
 	}
 
-	$result = DBselect('SELECT serviceupid FROM services_links WHERE servicedownid='.$serviceid);
+	$result = DBselect('SELECT serviceupid FROM services_links WHERE servicedownid='.zbx_dbstr($serviceid));
 
 	while($rows=DBfetch($result)){
 		$serviceupid =  $rows['serviceupid'];
@@ -790,9 +800,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 serviceid,algorithm FROM services WHERE triggerid='.$triggerid);
+	$result = DBselect('SELECT serviceid,algorithm FROM services WHERE triggerid='.zbx_dbstr($triggerid));
 
 	while(($rows=DBfetch($result))){
 //		$status = get_service_status($rows['serviceid'],$rows['algorithm'],$triggerid);
@@ -825,7 +835,7 @@
 
 	while($rows=DBfetch($result)){
 		$status = get_service_status($rows['serviceid'],$rows['algorithm'],$rows['triggerid']);
-		DBexecute('UPDATE services SET status = '.$status.' WHERE serviceid='.$rows['serviceid']);
+		DBexecute('UPDATE services SET status = '.zbx_dbstr($status).' WHERE serviceid='.zbx_dbstr($rows['serviceid']));
 
 		add_service_alarm($rows['serviceid'],$status,time());
 	}
@@ -850,7 +860,7 @@
 
 	$result = DBselect('SELECT servicealarmid, value '.
 						' FROM service_alarms '.
-						' WHERE serviceid='.$serviceid.
+						' WHERE serviceid='.zbx_dbstr($serviceid).
 						' ORDER BY servicealarmid DESC',1);
 	$rows = DBfetch($result);
 	if($rows && !is_null($rows['value']) && ($rows['value'] == $status)){
@@ -870,7 +880,7 @@
 		return true;
 	}
 
-	$result = DBexecute('INSERT INTO service_alarms (servicealarmid,serviceid,clock,value) VALUES ('.get_dbid('service_alarms','servicealarmid').','.$serviceid.','.$clock.','.$status.')');
+	$result = DBexecute('INSERT INTO service_alarms (servicealarmid,serviceid,clock,value) VALUES ('.get_dbid('service_alarms','servicealarmid').','.zbx_dbstr($serviceid).','.zbx_dbstr($clock).','.zbx_dbstr($status).')');
 
 	return $result;
 }
Index: frontends/php/include/graphs.inc.php
===================================================================
--- frontends/php/include/graphs.inc.php	(revision 38884)
+++ frontends/php/include/graphs.inc.php	(working copy)
@@ -121,7 +121,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)){
@@ -154,7 +154,7 @@
 		$db_graphs = DBselect('SELECT distinct g.* '.
 						' FROM graphs g, graphs_items gi '.
 						' WHERE g.graphid=gi.graphid '.
-							' AND gi.gitemid='.$gitemid);
+							' AND gi.gitemid='.zbx_dbstr($gitemid));
 
 	return DBfetch($db_graphs);
 	}
@@ -164,7 +164,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);
 	}
 
@@ -181,13 +181,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');
 	}
 
@@ -207,7 +207,7 @@
 
 		$sql = 	'SELECT g.graphid '.
 				' FROM graphs g, graphs_items gi, items i '.
-				' WHERE g.graphid='.$graphid.
+				' WHERE g.graphid='.zbx_dbstr($graphid).
 					' AND g.graphid=gi.graphid '.
 					' AND i.itemid=gi.itemid '.
 					' AND '.DBcondition('i.hostid',$available_hosts,true);
@@ -302,7 +302,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'];
@@ -389,7 +389,7 @@
 	}
 
 	function get_graphitem_by_gitemid($gitemid){
-		$result=DBselect('SELECT * FROM graphs_items WHERE gitemid='.$gitemid);
+		$result=DBselect('SELECT * FROM graphs_items WHERE gitemid='.zbx_dbstr($gitemid));
 		$row=DBfetch($result);
 		if($row){
 			return	$row;
@@ -400,7 +400,7 @@
 	}
 
 	function get_graphitem_by_itemid($itemid){
-		$result = DBfetch(DBselect('SELECT * FROM graphs_items WHERE itemid='.$itemid));
+		$result = DBfetch(DBselect('SELECT * FROM graphs_items WHERE itemid='.zbx_dbstr($itemid)));
 		$row=DBfetch($result);
 		if($row)
 		{
@@ -411,7 +411,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;
@@ -444,9 +444,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']);
@@ -487,8 +487,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);
 	}
@@ -608,28 +611,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;
@@ -701,7 +704,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(
@@ -833,8 +836,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 );
 	}
Index: frontends/php/include/db.inc.php
===================================================================
--- frontends/php/include/db.inc.php	(revision 38884)
+++ frontends/php/include/db.inc.php	(working copy)
@@ -846,7 +846,7 @@
 			default:
 				$items = array_chunk($array, 950);
 				foreach($items as $id => $values){
-					if($string) $values = zbx_dbstr($values);
+					$values = zbx_dbstr($values);
 
 					$condition.=!empty($condition)?')'.$concat.$fieldname.$in.'(':'';
 					$condition.= implode(',',$values);
Index: frontends/php/include/forms.inc.php
===================================================================
--- frontends/php/include/forms.inc.php	(revision 38884)
+++ frontends/php/include/forms.inc.php	(working copy)
@@ -39,12 +39,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(
@@ -159,7 +159,7 @@
 		$frm_title = S_DISCOVERY_RULE;
 
 		if(isset($_REQUEST['druleid'])){
-			if( ($rule_data = DBfetch(DBselect('SELECT * FROM drules WHERE druleid='.$_REQUEST['druleid']))))
+			if( ($rule_data = DBfetch(DBselect('SELECT * FROM drules WHERE druleid='.zbx_dbstr($_REQUEST['druleid'])))))
 				$frm_title = S_DISCOVERY_RULE.' "'.$rule_data['name'].'"';
 		}
 
@@ -184,7 +184,7 @@
 			$db_checks = DBselect('SELECT dcheckid,type,ports,key_,snmp_community,snmpv3_securityname,'.
 						'snmpv3_securitylevel,snmpv3_authpassphrase,snmpv3_privpassphrase'.
 						' FROM dchecks'.
-						' WHERE druleid='.$_REQUEST['druleid']);
+						' WHERE druleid='.zbx_dbstr($_REQUEST['druleid']));
 			while($check_data = DBfetch($db_checks)){
 				$count = array_push($dchecks, array('dcheckid' => $check_data['dcheckid'], 'type' => $check_data['type'],
 						'ports' => $check_data['ports'], 'key' => $check_data['key_'],
@@ -409,7 +409,7 @@
 
 		if((isset($_REQUEST["httptestid"]) && !isset($_REQUEST["form_refresh"])) || isset($limited)){
 			$httptest_data = DBfetch(DBselect("SELECT wt.*, a.name as application ".
-				" FROM httptest wt,applications a WHERE wt.httptestid=".$_REQUEST["httptestid"].
+				" FROM httptest wt,applications a WHERE wt.httptestid=".zbx_dbstr($_REQUEST["httptestid"]).
 				" AND a.applicationid=wt.applicationid"));
 
 			$name		= $httptest_data['name'];
@@ -424,7 +424,7 @@
 			$http_password 	= $httptest_data['http_password'];
 
 			$steps		= array();
-			$db_steps = DBselect('SELECT * FROM httpstep WHERE httptestid='.$_REQUEST["httptestid"].' order by no');
+			$db_steps = DBselect('SELECT * FROM httpstep WHERE httptestid='.zbx_dbstr($_REQUEST["httptestid"]).' order by no');
 			while($step_data = DBfetch($db_steps))
 			{
 				$steps[] = $step_data;
@@ -654,14 +654,14 @@
 			$sql = 'SELECT g.* '.
 					' FROM usrgrp g, users_groups ug '.
 					' WHERE ug.usrgrpid=g.usrgrpid '.
-						' AND ug.userid='.$userid;
+						' AND ug.userid='.zbx_dbstr($userid);
 			$db_user_groups = DBselect($sql);
 
 			while($db_group = DBfetch($db_user_groups)){
 				$user_groups[$db_group['usrgrpid']] = $db_group['usrgrpid'];
 			}
 
-			$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'],
 									'mediatypeid' => $db_media['mediatypeid'],
@@ -968,7 +968,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);
 
@@ -980,7 +980,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)){
@@ -1042,7 +1042,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.
@@ -2185,7 +2185,7 @@
 			if(isset($limited) && $type != ITEM_TYPE_HTTPTEST){
 				$frmItem->addVar('valuemapid', $valuemapid);
 				$map_name = S_AS_IS;
-				if($map_data = DBfetch(DBselect('SELECT name FROM valuemaps WHERE valuemapid='.$valuemapid))){
+				if($map_data = DBfetch(DBselect('SELECT name FROM valuemaps WHERE valuemapid='.zbx_dbstr($valuemapid)))){
 					$map_name = $map_data['name'];
 				}
 				$cmbMap = new CTextBox('valuemap_name', $map_name, 20, 'yes');
@@ -2233,7 +2233,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)){
@@ -2477,7 +2477,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)){
@@ -2703,7 +2703,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;
@@ -2905,7 +2905,7 @@
 
 		$trigger = DBfetch(DBselect('SELECT t.*, h.* '.
 			' FROM triggers t, functions f, items i, hosts h '.
-			' WHERE t.triggerid='.$triggerid.
+			' WHERE t.triggerid='.zbx_dbstr($triggerid).
 				' AND f.triggerid=t.triggerid '.
 				' AND f.itemid=i.itemid '.
 				' AND i.hostid=h.hostid '));
@@ -3480,7 +3480,7 @@
 		if(isset($_REQUEST['maintenanceid']) && !isset($_REQUEST['form_refresh'])){
 			$sql_from = ', maintenances_hosts mh ';
 			$sql_where = ' AND h.hostid=mh.hostid '.
-							' AND mh.maintenanceid='.$_REQUEST['maintenanceid'];
+							' AND mh.maintenanceid='.zbx_dbstr($_REQUEST['maintenanceid']);
 		}
 		else{
 			$sql_from = '';
@@ -3533,7 +3533,7 @@
 		if(isset($_REQUEST['maintenanceid']) && !isset($_REQUEST["form_refresh"])){
 			$sql_from = ', maintenances_groups mg ';
 			$sql_where = ' AND g.groupid=mg.groupid '.
-							' AND mg.maintenanceid='.$_REQUEST['maintenanceid'];
+							' AND mg.maintenanceid='.zbx_dbstr($_REQUEST['maintenanceid']);
 		}
 		else{
 			$sql_from = '';
@@ -3583,7 +3583,7 @@
 			$timeperiods = array();
 			$sql = 'SELECT DISTINCT mw.maintenanceid, tp.* '.
 					' FROM timeperiods tp, maintenances_windows mw '.
-					' WHERE mw.maintenanceid='.$_REQUEST['maintenanceid'].
+					' WHERE mw.maintenanceid='.zbx_dbstr($_REQUEST['maintenanceid']).
 						' AND tp.timeperiodid=mw.timeperiodid '.
 					' ORDER BY tp.timeperiod_type ASC';
 			$db_timeperiods = DBselect($sql);
@@ -4121,7 +4121,7 @@
 			/* prepare conditions */
 			$sql = 'SELECT conditiontype, operator, value '.
 					' FROM conditions '.
-					' WHERE actionid='.$_REQUEST['actionid'].
+					' WHERE actionid='.zbx_dbstr($_REQUEST['actionid']).
 					' ORDER BY conditiontype,conditionid';
 			$db_conditions = DBselect($sql);
 			while($condition_data = DBfetch($db_conditions)){
@@ -4470,7 +4470,7 @@
 			/* prepate operations */
 			$sql = 'SELECT * '.
 					' FROM operations'.
-					' WHERE actionid='.$_REQUEST['actionid'].
+					' WHERE actionid='.zbx_dbstr($_REQUEST['actionid']).
 					' ORDER BY esc_step_from,operationtype,object,operationid';
 			$db_operations = DBselect($sql);
 
@@ -4490,14 +4490,14 @@
 
 				$operation_data['opconditions'] = array();
 
-				$sql = 'SELECT * FROM opconditions WHERE operationid='.$operation_data['operationid'];
+				$sql = 'SELECT * FROM opconditions WHERE operationid='.zbx_dbstr($operation_data['operationid']);
 				$db_opconds = DBselect($sql);
 				while($db_opcond = DBfetch($db_opconds)){
 
 					$operation_data['opconditions'][] = $db_opcond;
 				}
 
-				$sql = 'SELECT * from opmediatypes WHERE operationid='.$operation_data['operationid'];
+				$sql = 'SELECT * from opmediatypes WHERE operationid='.zbx_dbstr($operation_data['operationid']);
 				$db_opmtypes = DBSelect($sql);
 				if($db_opmtype = DBfetch($db_opmtypes)){
 					$operation_data['mediatypeid'] = $db_opmtype['mediatypeid'];
@@ -4753,7 +4753,7 @@
 							' FROM media_type mt, media m '.
 							' WHERE '.DBin_node('mt.mediatypeid').
 								' AND m.mediatypeid=mt.mediatypeid '.
-								' AND m.userid='.$new_operation['objectid'].
+								' AND m.userid='.zbx_dbstr($new_operation['objectid']).
 								' AND m.active='.ACTION_STATUS_ENABLED.
 							' ORDER BY mt.description';
 					$db_mediatypes = DBselect($sql);
@@ -4781,8 +4781,8 @@
 							' FROM media_type mt,media m '.
 							' WHERE '.DBin_node('mt.mediatypeid').
 								' AND mt.mediatypeid=m.mediatypeid '.
-								' AND m.userid='.$new_operation['objectid'].
-								($new_operation['mediatypeid'] ? ' AND m.mediatypeid='.$new_operation['mediatypeid'] : '').
+								' AND m.userid='.zbx_dbstr($new_operation['objectid']).
+								($new_operation['mediatypeid'] ? ' AND m.mediatypeid='.zbx_dbstr($new_operation['mediatypeid']) : '').
 								' AND m.active='.ACTION_STATUS_ENABLED.
 							' ORDER BY mt.description,m.sendto';
 					$db_medias = DBselect($sql);
@@ -4847,7 +4847,7 @@
 				$tblOper->addItem(new CVar('new_operation[shortdata]',''));
 				$tblOper->addItem(new CVar('new_operation[longdata]',''));
 
-				if($object_name= DBfetch(DBselect('select name FROM groups WHERE groupid='.$new_operation['objectid']))){
+				if($object_name= DBfetch(DBselect('select name FROM groups WHERE groupid='.zbx_dbstr($new_operation['objectid'])))){
 					$object_name = $object_name['name'];
 				}
 				$tblNewOperation->addRow(array(S_GROUP, array(
@@ -4866,7 +4866,7 @@
 				$tblOper->addItem(new CVar('new_operation[shortdata]',''));
 				$tblOper->addItem(new CVar('new_operation[longdata]',''));
 
-				if($object_name= DBfetch(DBselect('select name FROM groups WHERE groupid='.$new_operation['objectid']))){
+				if($object_name= DBfetch(DBselect('select name FROM groups WHERE groupid='.zbx_dbstr($new_operation['objectid'])))){
 					$object_name = $object_name['name'];
 				}
 				$tblNewOperation->addRow(array(S_GROUP, array(
@@ -4886,7 +4886,7 @@
 				$tblOper->addItem(new CVar('new_operation[longdata]',''));
 
 				if($object_name= DBfetch(DBselect('SELECT host FROM hosts '.
-					' WHERE status='.HOST_STATUS_TEMPLATE.' AND hostid='.$new_operation['objectid'])))
+					' WHERE status='.HOST_STATUS_TEMPLATE.' AND hostid='.zbx_dbstr($new_operation['objectid']))))
 				{
 					$object_name = $object_name['host'];
 				}
@@ -4907,7 +4907,7 @@
 				$tblOper->addItem(new CVar('new_operation[longdata]',''));
 
 				if($object_name= DBfetch(DBselect('SELECT host FROM hosts '.
-					' WHERE status='.HOST_STATUS_TEMPLATE.' AND hostid='.$new_operation['objectid'])))
+					' WHERE status='.HOST_STATUS_TEMPLATE.' AND hostid='.zbx_dbstr($new_operation['objectid']))))
 				{
 					$object_name = $object_name['host'];
 				}
@@ -5110,7 +5110,7 @@
 		$password	= get_request('password','');
 
 		if(isset($_REQUEST['mediatypeid']) && !isset($_REQUEST['form_refresh'])){
-			$result = DBselect('select * FROM media_type WHERE mediatypeid='.$_REQUEST['mediatypeid']);
+			$result = DBselect('select * FROM media_type WHERE mediatypeid='.zbx_dbstr($_REQUEST['mediatypeid']));
 
 			$row = DBfetch($result);
 			$mediatypeid	= $row['mediatypeid'];
@@ -5202,7 +5202,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'].'"';
 		}
@@ -5701,7 +5701,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);
@@ -5724,7 +5724,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';
 			}
@@ -5916,7 +5916,7 @@
 
 			$sql = 'SELECT * '.
 					' FROM items '.
-					' WHERE hostid='.$_REQUEST['hostid'].
+					' WHERE hostid='.zbx_dbstr($_REQUEST['hostid']).
 						' AND templateid=0 '.
 					' ORDER BY description';
 			$host_items_res = DBselect($sql);
@@ -5936,7 +5936,7 @@
 
 			$sql = 'SELECT DISTINCT t.* '.
 					' FROM triggers t, items i, functions f'.
-					' WHERE i.hostid='.$_REQUEST['hostid'].
+					' WHERE i.hostid='.zbx_dbstr($_REQUEST['hostid']).
 						' AND f.itemid=i.itemid '.
 						' AND t.triggerid=f.triggerid '.
 						' AND '.DBcondition('t.triggerid', $available_triggers).
@@ -5965,7 +5965,7 @@
 							' AND gi.graphid=g.graphid '.
 							' AND g.templateid=0 '.
 							' AND i.itemid=gi.itemid '.
-							' AND i.hostid='.$_REQUEST['hostid'].
+							' AND i.hostid='.zbx_dbstr($_REQUEST['hostid']).
 						' ORDER BY g.name';
 
 			$host_graph_res = DBselect($sql);
@@ -6137,7 +6137,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)) {
@@ -6179,7 +6179,7 @@
 
 		$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) {
@@ -6260,7 +6260,7 @@
 		else{
 			$sql = 'SELECT DISTINCT h.hostid,h.host '.
 				' FROM hosts h,hosts_templates ht'.
-				' WHERE (ht.templateid='.$_REQUEST['hostid'].
+				' WHERE (ht.templateid='.zbx_dbstr($_REQUEST['hostid']).
 					' AND h.hostid=ht.hostid'.
 					' AND h.status IN ('.HOST_STATUS_MONITORED.','.HOST_STATUS_NOT_MONITORED.','.HOST_STATUS_TEMPLATE.') '.
 					' AND '.DBcondition('h.hostid',$available_hosts).' )'.
@@ -6278,7 +6278,7 @@
 			' FROM hosts h, hosts_groups hg'.
  			' WHERE ( h.status IN ('.HOST_STATUS_MONITORED.','.HOST_STATUS_NOT_MONITORED.','.HOST_STATUS_TEMPLATE.') '.
  				' AND '.DBcondition('h.hostid',$available_hosts).
-				' AND hg.groupid='.$selected_grp.
+				' AND hg.groupid='.zbx_dbstr($selected_grp).
 				' AND h.hostid=hg.hostid)'.
 				' OR '.DBcondition('h.hostid', $hosts_in_tpl).
  			' ORDER BY h.host';
@@ -6327,7 +6327,7 @@
 		$frm_title = 'New system map';
 
 		if(isset($_REQUEST['sysmapid'])){
-			$result=DBselect('SELECT * FROM sysmaps WHERE sysmapid='.$_REQUEST['sysmapid']);
+			$result=DBselect('SELECT * FROM sysmaps WHERE sysmapid='.zbx_dbstr($_REQUEST['sysmapid']));
 			$row=DBfetch($result);
 			$frm_title = 'System map: "'.$row['name'].'"';
 		}
@@ -6417,7 +6417,7 @@
 
 		$sql = 'SELECT name '.
 				' FROM scripts '.
-				' WHERE scriptid='.$scriptid;
+				' WHERE scriptid='.zbx_dbstr($scriptid);
 		$script_info = DBfetch(DBselect($sql));
 
 		$frmResult = new CFormTable($script_info['name'].': '.script_make_command($scriptid,$hostid));
@@ -6439,7 +6439,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'].']';
@@ -6451,7 +6451,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);
@@ -6595,7 +6595,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/maps.inc.php
===================================================================
--- frontends/php/include/maps.inc.php	(revision 38884)
+++ frontends/php/include/maps.inc.php	(working copy)
@@ -82,7 +82,7 @@
 
 		$sql = 'SELECT * '.
 				' FROM sysmaps_elements '.
-				' WHERE sysmapid='.$sysmapid.
+				' WHERE sysmapid='.zbx_dbstr($sysmapid).
 					' AND '.DBin_node('sysmapid', $nodes);
 		$db_result = DBselect($sql);
 		$available_hosts = get_accessible_hosts_by_user($USER_DETAILS,$perm,PERM_RES_IDS_ARRAY,get_current_nodeid(true));
@@ -117,7 +117,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;
 		}
@@ -126,7 +126,7 @@
 	}
 
 	function get_sysmaps_element_by_selementid($selementid){
-		$sql='select * FROM sysmaps_elements WHERE selementid='.$selementid;
+		$sql='select * FROM sysmaps_elements WHERE selementid='.zbx_dbstr($selementid);
 		$result=DBselect($sql);
 		$row=DBfetch($result);
 		if($row){
@@ -144,7 +144,7 @@
 		$sysmapid=get_dbid('sysmaps','sysmapid');
 
 		$result=DBexecute('insert into sysmaps (sysmapid,name,width,height,backgroundid,highlight,label_type,label_location)'.
-			' VALUES ('.$sysmapid.','.zbx_dbstr($name).','.$width.','.$height.','.$backgroundid.','.$highlight.','.$label_type.','.$label_location.')');
+			' VALUES ('.$sysmapid.','.zbx_dbstr($name).','.zbx_dbstr($width).','.zbx_dbstr($height).','.zbx_dbstr($backgroundid).','.zbx_dbstr($highlight).','.zbx_dbstr($label_type).','.zbx_dbstr($label_location).')');
 
 		if(!$result)
 			return $result;
@@ -155,9 +155,9 @@
 // Update System Map
 
 	function update_sysmap($sysmapid,$name,$width,$height,$backgroundid,$highlight,$label_type,$label_location){
-		return	DBexecute('UPDATE sysmaps SET name='.zbx_dbstr($name).',width='.$width.',height='.$height.','.
-			'backgroundid='.$backgroundid.',highlight='.$highlight.',label_type='.$label_type.','.
-			'label_location='.$label_location.' WHERE sysmapid='.$sysmapid);
+		return	DBexecute('UPDATE sysmaps SET name='.zbx_dbstr($name).',width='.zbx_dbstr($width).',height='.zbx_dbstr($height).','.
+			'backgroundid='.zbx_dbstr($backgroundid).',highlight='.zbx_dbstr($highlight).',label_type='.zbx_dbstr($label_type).','.
+			'label_location='.zbx_dbstr($label_location).' WHERE sysmapid='.zbx_dbstr($sysmapid));
 	}
 
 // Delete System Map
@@ -212,9 +212,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;
@@ -251,13 +251,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;
 	}
 
@@ -273,7 +273,7 @@
 	function get_link_triggers($linkid){
 		$triggers = array();
 
-		$sql = 'SELECT * FROM sysmaps_link_triggers WHERE linkid='.$linkid;
+		$sql = 'SELECT * FROM sysmaps_link_triggers WHERE linkid='.zbx_dbstr($linkid);
 		$res = DBselect($sql);
 
 		while($rows = DBfetch($res)){
@@ -285,7 +285,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);
 	}
 
@@ -296,7 +296,7 @@
 	}
 
 	function delete_link_trigger($linkid,$triggerid){
-	return DBexecute('DELETE FROM sysmaps_link_triggers WHERE linkid='.$linkid.' AND triggerid='.$triggerid);
+	return DBexecute('DELETE FROM sysmaps_link_triggers WHERE linkid='.zbx_dbstr($linkid).' AND triggerid='.zbx_dbstr($triggerid));
 	}
 
 	function delete_all_link_triggers($linkids){
@@ -323,7 +323,7 @@
 
 		$db_elements = DBselect('SELECT elementid, elementtype '.
 						' FROM sysmaps_elements '.
-						' WHERE sysmapid='.$elementid);
+						' WHERE sysmapid='.zbx_dbstr($elementid));
 
 		while($element = DBfetch($db_elements))
 		{
@@ -367,11 +367,11 @@
 		$result = DBexecute('INSERT INTO sysmaps_elements '.
 							'(selementid,sysmapid,elementid,elementtype,label,label_location,'.
 							'iconid_off,iconid_on,iconid_unknown,iconid_maintenance,iconid_disabled,x,y,url)'.
-						' VALUES ('.$selementid.','.$selement['sysmapid'].','.$selement['elementid'].','.
-									$selement['elementtype'].','.zbx_dbstr($selement['label']).','.$selement['label_location'].','.
-									$selement['iconid_off'].','.$selement['iconid_on'].','.$selement['iconid_unknown'].','.
-									$selement['iconid_maintenance'].','.$selement['iconid_disabled'].','.
-									$selement['x'].','.$selement['y'].','.zbx_dbstr($selement['url']).')');
+						' VALUES ('.$selementid.','.zbx_dbstr($selement['sysmapid']).','.zbx_dbstr($selement['elementid']).','.
+							zbx_dbstr($selement['elementtype']).','.zbx_dbstr($selement['label']).','.zbx_dbstr($selement['label_location']).','.
+							zbx_dbstr($selement['iconid_off']).','.zbx_dbstr($selement['iconid_on']).','.zbx_dbstr($selement['iconid_unknown']).','.
+							zbx_dbstr($selement['iconid_maintenance']).','.zbx_dbstr($selement['iconid_disabled']).','.
+							zbx_dbstr($selement['x']).','.zbx_dbstr($selement['y']).','.zbx_dbstr($selement['url']).')');
 
 		if(!$result)
 			return $result;
@@ -410,19 +410,19 @@
 		}
 
 		return	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']));
 	}
 
 	/******************************************************************************
@@ -718,7 +718,7 @@
 	}
 
 	function get_png_by_selementid($selementid){
-		$selement = DBfetch(DBselect('SELECT * FROM sysmaps_elements WHERE selementid='.$selementid));
+		$selement = DBfetch(DBselect('SELECT * FROM sysmaps_elements WHERE selementid='.zbx_dbstr($selementid)));
 		if(!$selement)	return FALSE;
 
 	return get_png_by_selement($selement);
@@ -890,14 +890,14 @@
 						zbx_strstr($label, '{HOST.CONN}'))
 				{
 					if($db_element['elementtype'] == SYSMAP_ELEMENT_TYPE_HOST){
-						$sql =' SELECT * FROM hosts WHERE hostid='.$db_element['elementid'];
+						$sql =' SELECT * FROM hosts WHERE hostid='.zbx_dbstr($db_element['elementid']);
 					}
 					else if($db_element['elementtype'] == SYSMAP_ELEMENT_TYPE_TRIGGER)
 						$sql =	'SELECT h.* '.
 							' FROM hosts h,items i,functions f '.
 							' WHERE h.hostid=i.hostid '.
 								' AND i.itemid=f.itemid '.
-								' AND f.triggerid='.$db_element['elementid'];
+								' AND f.triggerid='.zbx_dbstr($db_element['elementid']);
 					else{
 // Should never be here
 					}
@@ -1012,7 +1012,7 @@
 			if(0 == strcmp($function, 'last')){
 				$sql = 'SELECT value '.
 						' FROM '.$history_table.
-						' WHERE itemid='.$db_item['itemid'].
+						' WHERE itemid='.zbx_dbstr($db_item['itemid']).
 						' ORDER BY '.$order_field.' DESC';
 
 				$result = DBselect($sql, 1);
@@ -1042,7 +1042,7 @@
 				$sql = 'SELECT '.$function.'(value) as value '.
 						' FROM '.$history_table.
 						' WHERE clock>'.$now.
-							' AND itemid='.$db_item['itemid'];
+							' AND itemid='.zbx_dbstr($db_item['itemid']);
 
 				$result = DBselect($sql);
 				if(NULL == ($row = DBfetch($result)) || is_null($row['value']))
@@ -1133,7 +1133,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/actions.inc.php
===================================================================
--- frontends/php/include/actions.inc.php	(revision 38884)
+++ frontends/php/include/actions.inc.php	(working copy)
@@ -27,13 +27,13 @@
 
 	$result = false;
 
-	if(DBselect('select actionid from actions where actionid='.$actionid.' and '.DBin_node('actionid'))){
+	if(DBselect('select actionid from actions where actionid='.zbx_dbstr($actionid).' and '.DBin_node('actionid'))){
 		$result = true;
 
 		$available_hosts = get_accessible_hosts_by_user($USER_DETAILS,$perm,null,get_current_nodeid(true));
 		$available_groups = get_accessible_groups_by_user($USER_DETAILS,$perm,null,get_current_nodeid(true));
 
-		$db_result = DBselect('SELECT * FROM conditions WHERE actionid='.$actionid);
+		$db_result = DBselect('SELECT * FROM conditions WHERE actionid='.zbx_dbstr($actionid));
 		while(($ac_data = DBfetch($db_result)) && $result){
 			if($ac_data['operator'] != 0) continue;
 
@@ -52,7 +52,7 @@
 				case CONDITION_TYPE_TRIGGER:
 					$sql = 'SELECT DISTINCT t.triggerid'.
 						' FROM triggers t,items i,functions f '.
-						' WHERE t.triggerid='.$ac_data['value'].
+						' WHERE t.triggerid='.zbx_dbstr($ac_data['value']).
 							' AND f.triggerid=t.triggerid'.
 							' AND i.itemid=f.itemid '.
 							' AND '.DBcondition('i.hostid',$available_hosts, true);
@@ -135,7 +135,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)){
@@ -148,7 +148,7 @@
 }
 
 function get_operations_by_actionid($actionid){
-	$sql='SELECT * FROM operations WHERE actionid='.$actionid;
+	$sql='SELECT * FROM operations WHERE actionid='.zbx_dbstr($actionid);
 	$result=DBselect($sql);
 
 return	$result;
@@ -161,9 +161,9 @@
 	$conditionid = get_dbid("conditions","conditionid");
 
 	$result = DBexecute('INSERT INTO conditions (conditionid,actionid,conditiontype,operator,value)'.
-		' values ('.$conditionid.','.$actionid.','.
-			$condition['type'].','.
-			$condition['operator'].','.
+		' values ('.$conditionid.','.zbx_dbstr($actionid).','.
+			zbx_dbstr($condition['type']).','.
+			zbx_dbstr($condition['operator']).','.
 			zbx_dbstr($condition['value']).
 		')');
 
@@ -180,17 +180,17 @@
 	if(!isset($operation['opconditions'])) $operation['opconditions'] = array();
 
 	$result = DBexecute('INSERT INTO operations (operationid, actionid, operationtype, object, objectid, shortdata, longdata, esc_period, esc_step_from, esc_step_to, default_msg, evaltype)'.
-		' values('.$operationid.','.$actionid.','.
-			$operation['operationtype'].','.
-			$operation['object'].','.
-			$operation['objectid'].','.
+		' values('.$operationid.','.zbx_dbstr($actionid).','.
+			zbx_dbstr($operation['operationtype']).','.
+			zbx_dbstr($operation['object']).','.
+			zbx_dbstr($operation['objectid']).','.
 			zbx_dbstr($operation['shortdata']).','.
 			zbx_dbstr($operation['longdata']).','.
-			$operation['esc_period'].','.
-			$operation['esc_step_from'].','.
-			$operation['esc_step_to'].','.
-			$operation['default_msg'].','.
-			$operation['evaltype'].
+			zbx_dbstr($operation['esc_period']).','.
+			zbx_dbstr($operation['esc_step_from']).','.
+			zbx_dbstr($operation['esc_step_to']).','.
+			zbx_dbstr($operation['default_msg']).','.
+			zbx_dbstr($operation['evaltype']).
 		')');
 	if(!$result)
 		return $result;
@@ -210,9 +210,9 @@
 
 	$result = DBexecute('INSERT INTO opconditions (opconditionid,operationid,conditiontype,operator,value)'.
 		' values ('.$opconditionid.','.
-			$operationid.','.
-			$opcondition['conditiontype'].','.
-			$opcondition['operator'].','.
+			zbx_dbstr($operationid).','.
+			zbx_dbstr($opcondition['conditiontype']).','.
+			zbx_dbstr($opcondition['operator']).','.
 			zbx_dbstr($opcondition['value']).
 		')');
 
@@ -230,7 +230,7 @@
 	$opmediatypeid = get_dbid('opmediatypes', 'opmediatypeid');
 
 	$result = DBexecute('INSERT INTO opmediatypes (opmediatypeid,operationid,mediatypeid)'.
-		' values ('.$opmediatypeid.','.$operationid.','.$mediatypeid.')');
+		' values ('.$opmediatypeid.','.zbx_dbstr($operationid).','.zbx_dbstr($mediatypeid).')');
 
 	if(!$result)
 		return $result;
@@ -266,7 +266,7 @@
 	$actionid=get_dbid('actions','actionid');
 
 	$result = DBexecute('INSERT INTO actions (actionid,name,eventsource,esc_period,def_shortdata,def_longdata,recovery_msg,r_shortdata,r_longdata,evaltype,status)'.
-				' VALUES ('.$actionid.','.zbx_dbstr($name).','.$eventsource.','.$esc_period.','.zbx_dbstr($def_shortdata).','.zbx_dbstr($def_longdata).','.$recovery_msg.','.zbx_dbstr($r_shortdata).','.zbx_dbstr($r_longdata).','.$evaltype.','.$status.')');
+				' VALUES ('.$actionid.','.zbx_dbstr($name).','.zbx_dbstr($eventsource).','.zbx_dbstr($esc_period).','.zbx_dbstr($def_shortdata).','.zbx_dbstr($def_longdata).','.zbx_dbstr($recovery_msg).','.zbx_dbstr($r_shortdata).','.zbx_dbstr($r_longdata).','.zbx_dbstr($evaltype).','.zbx_dbstr($status).')');
 
 	foreach($operations as $operation)
 		if(!$result = add_action_operation($actionid, $operation))
@@ -313,26 +313,26 @@
 	}
 
 	$result = DBexecute('UPDATE actions SET name='.zbx_dbstr($name).
-							',eventsource='.$eventsource.
-							',esc_period='.$esc_period.
+							',eventsource='.zbx_dbstr($eventsource).
+							',esc_period='.zbx_dbstr($esc_period).
 							',def_shortdata='.zbx_dbstr($def_shortdata).
 							',def_longdata='.zbx_dbstr($def_longdata).
-							',recovery_msg='.$recovery_msg.
+							',recovery_msg='.zbx_dbstr($recovery_msg).
 							',r_shortdata='.zbx_dbstr($r_shortdata).
 							',r_longdata='.zbx_dbstr($r_longdata).
-							',evaltype='.$evaltype.
-							',status='.$status.
-						' WHERE actionid='.$actionid);
+							',evaltype='.zbx_dbstr($evaltype).
+							',status='.zbx_dbstr($status).
+						' WHERE actionid='.zbx_dbstr($actionid));
 
 	if($result){
-		DBexecute('DELETE FROM conditions WHERE actionid='.$actionid);
+		DBexecute('DELETE FROM conditions WHERE actionid='.zbx_dbstr($actionid));
 
 		$opers = get_operations_by_actionid($actionid);
 		while($operation = DBFetch($opers)){
-			DBexecute('DELETE FROM opconditions WHERE operationid='.$operation['operationid']);
-			DBexecute('DELETE FROM opmediatypes WHERE operationid='.$operation['operationid']);
+			DBexecute('DELETE FROM opconditions WHERE operationid='.zbx_dbstr($operation['operationid']));
+			DBexecute('DELETE FROM opmediatypes WHERE operationid='.zbx_dbstr($operation['operationid']));
 		}
-		DBexecute('DELETE FROM operations WHERE actionid='.$actionid);
+		DBexecute('DELETE FROM operations WHERE actionid='.zbx_dbstr($actionid));
 
 
 		foreach($operations as $operation)
@@ -352,7 +352,7 @@
 // Delete Action
 
 function delete_action( $actionid ){
-	$return = DBexecute('delete from conditions where actionid='.$actionid);
+	$return = DBexecute('delete from conditions where actionid='.zbx_dbstr($actionid));
 
 	$opers = get_operations_by_actionid($actionid);
 	while($operation = DBFetch($opers)){
@@ -361,13 +361,13 @@
 	}
 
 	if($return)
-		$result = DBexecute('delete from operations where actionid='.$actionid);
+		$result = DBexecute('delete from operations where actionid='.zbx_dbstr($actionid));
 
 	if($return)
-		$result = DBexecute('delete from alerts where actionid='.$actionid);
+		$result = DBexecute('delete from alerts where actionid='.zbx_dbstr($actionid));
 
 	if($return)
-		$result = DBexecute('delete from actions where actionid='.$actionid);
+		$result = DBexecute('delete from actions where actionid='.zbx_dbstr($actionid));
 
 return $result;
 }
@@ -474,7 +474,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;
@@ -597,7 +597,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";
@@ -839,7 +839,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){
@@ -861,7 +861,7 @@
 			}
 			break;
 		case CONDITION_TYPE_TRIGGER:
-			if( !DBfetch(DBselect('select triggerid from triggers where triggerid='.$value)) ||
+			if( !DBfetch(DBselect('select triggerid from triggers where triggerid='.zbx_dbstr($value))) ||
 				!check_right_on_trigger_by_triggerid(PERM_READ_ONLY, $value) )
 			{
 				error(S_INCORRECT_TRIGGER);
@@ -1259,7 +1259,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';
@@ -1293,8 +1293,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).
@@ -1349,7 +1349,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));
@@ -1359,7 +1359,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;
 
@@ -1369,7 +1369,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;
 
@@ -1378,7 +1378,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;
 
@@ -1416,7 +1416,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.')';
 
 
@@ -1425,7 +1425,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;
 
@@ -1441,7 +1441,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;
 
@@ -1457,7 +1457,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)
@@ -29,10 +29,10 @@
 
 		$result = false;
 
-		if(DBfetch(DBselect('SELECT screenid FROM screens WHERE screenid='.$screenid.' AND '.DBin_node('screenid', get_current_nodeid($perm))))){
+		if(DBfetch(DBselect('SELECT screenid FROM screens WHERE screenid='.zbx_dbstr($screenid).' AND '.DBin_node('screenid', get_current_nodeid($perm))))){
 			$result = true;
 
-			$db_result = DBselect('SELECT * FROM screens_items WHERE screenid='.$screenid);
+			$db_result = DBselect('SELECT * FROM screens_items WHERE screenid='.zbx_dbstr($screenid));
 			while(($ac_data = DBfetch($db_result)) && $result){
 				if($ac_data['resourceid'] == 0) continue;
 
@@ -113,16 +113,16 @@
 	}
 */
 	function delete_screen($screenid){
-		$result=DBexecute('DELETE FROM screens_items where screenid='.$screenid);
-		$result&=DBexecute('DELETE FROM screens_items where resourceid='.$screenid.' and resourcetype='.SCREEN_RESOURCE_SCREEN);
-		$result&=DBexecute('DELETE FROM slides where screenid='.$screenid);
-		$result&=DBexecute("DELETE FROM profiles WHERE idx='web.favorite.screenids' AND source='screenid' AND value_id=$screenid");
-		$result&=DBexecute('DELETE FROM screens where screenid='.$screenid);
+		$result=DBexecute('DELETE FROM screens_items where screenid='.zbx_dbstr($screenid));
+		$result&=DBexecute('DELETE FROM screens_items where resourceid='.zbx_dbstr($screenid).' and resourcetype='.SCREEN_RESOURCE_SCREEN);
+		$result&=DBexecute('DELETE FROM slides where screenid='.zbx_dbstr($screenid));
+		$result&=DBexecute("DELETE FROM profiles WHERE idx='web.favorite.screenids' AND source='screenid' AND value_id=".zbx_dbstr($screenid));
+		$result&=DBexecute('DELETE FROM screens where screenid='.zbx_dbstr($screenid));
 	return	$result;
 	}
 
 	function add_screen_item($resourcetype,$screenid,$x,$y,$resourceid,$width,$height,$colspan,$rowspan,$elements,$valign,$halign,$style,$url,$dynamic){
-		$sql='DELETE FROM screens_items WHERE screenid='.$screenid.' and x='.$x.' and y='.$y;
+		$sql='DELETE FROM screens_items WHERE screenid='.zbx_dbstr($screenid).' and x='.zbx_dbstr($x).' and y='.zbx_dbstr($y);
 		DBexecute($sql);
 
 		$screenitemid=get_dbid("screens_items","screenitemid");
@@ -130,8 +130,8 @@
 							'(screenitemid,resourcetype,screenid,x,y,resourceid,width,height,'.
 							' colspan,rowspan,elements,valign,halign,style,url,dynamic) '.
 						' VALUES '.
-							"($screenitemid,$resourcetype,$screenid,$x,$y,$resourceid,$width,$height,$colspan,".
-							"$rowspan,$elements,$valign,$halign,$style,".zbx_dbstr($url).",$dynamic)");
+							"(".zbx_dbstr($screenitemid).",".zbx_dbstr($resourcetype).",".zbx_dbstr($screenid).",".zbx_dbstr($x).",".zbx_dbstr($y).",".zbx_dbstr($resourceid).",".zbx_dbstr($width).",".zbx_dbstr($height).",".zbx_dbstr($colspan).",".
+							zbx_dbstr($rowspan).",".zbx_dbstr($elements).",".zbx_dbstr($valign).",".zbx_dbstr($halign).",".zbx_dbstr($style).",".zbx_dbstr($url).",".zbx_dbstr($dynamic).")");
 
 		if(!$result) return $result;
 	return $screenitemid;
@@ -139,19 +139,19 @@
 
 	function update_screen_item($screenitemid,$resourcetype,$resourceid,$width,$height,$colspan,$rowspan,$elements,$valign,$halign,$style,$url,$dynamic){
 		return  DBexecute("UPDATE screens_items SET ".
-							"resourcetype=$resourcetype,"."resourceid=$resourceid,"."width=$width,".
-							"height=$height,colspan=$colspan,rowspan=$rowspan,elements=$elements,".
-							"valign=$valign,halign=$halign,style=$style,url=".zbx_dbstr($url).",dynamic=$dynamic".
-						" WHERE screenitemid=$screenitemid");
+							"resourcetype=".zbx_dbstr($resourcetype).","."resourceid=".zbx_dbstr($resourceid).","."width=".zbx_dbstr($width).",".
+							"height=".zbx_dbstr($height).",colspan=".zbx_dbstr($colspan).",rowspan=".zbx_dbstr($rowspan).",elements=".zbx_dbstr($elements).",".
+							"valign=".zbx_dbstr($valign).",halign=".zbx_dbstr($halign).",style=".zbx_dbstr($style).",url=".zbx_dbstr($url).",dynamic=".zbx_dbstr($dynamic).
+						" WHERE screenitemid=".zbx_dbstr($screenitemid));
 	}
 
 	function delete_screen_item($screenitemid){
-		$sql="DELETE FROM screens_items where screenitemid=$screenitemid";
+		$sql="DELETE FROM screens_items where screenitemid=".zbx_dbstr($screenitemid);
 	return  DBexecute($sql);
 	}
 
 	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;
@@ -163,8 +163,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;
@@ -175,7 +174,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;
@@ -191,9 +190,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;
@@ -205,7 +204,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;
@@ -213,7 +212,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'];
@@ -236,7 +235,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 validate_slide(&$slide){
@@ -253,7 +252,7 @@
 
 		$slideshowid = get_dbid('slideshows','slideshowid');
 		$result = DBexecute('INSERT INTO slideshows (slideshowid,name,delay) '.
-							' VALUES ('.$slideshowid.','.zbx_dbstr($name).','.$delay.')');
+							' VALUES ('.$slideshowid.','.zbx_dbstr($name).','.zbx_dbstr($delay).')');
 
 		$i = 0;
 		foreach($slides as $num => $slide){
@@ -261,7 +260,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;
 		}
 
@@ -274,17 +273,17 @@
 				return false;
 		}
 
-		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;
 			}
@@ -295,9 +294,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;
 	}
@@ -346,7 +345,7 @@
 		$sql='SELECT h.clock,h.value,i.valuemapid '.
 				' FROM '.$history_table.' h, items i '.
 				' WHERE h.itemid=i.itemid '.
-					' AND i.itemid='.$itemid.
+					' AND i.itemid='.zbx_dbstr($itemid).
 				' ORDER BY h.'.$order_field.' DESC';
 		$result=DBselect($sql,$elements);
 		while($row=DBfetch($result)){
@@ -408,13 +407,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;
 		}
@@ -432,8 +431,8 @@
 
 		if(isset($_REQUEST['screenitemid'])){
 			$iresult=DBSelect('SELECT * FROM screens_items'.
-							' WHERE screenid='.$_REQUEST['screenid'].
-								' AND screenitemid='.$_REQUEST['screenitemid']
+							' WHERE screenid='.zbx_dbstr($_REQUEST['screenid']).
+								' AND screenitemid='.zbx_dbstr($_REQUEST['screenitemid'])
 							);
 
 			$form->addVar('screenitemid',$_REQUEST['screenitemid']);
@@ -510,7 +509,7 @@
 							' LEFT JOIN items i ON gi.itemid=i.itemid '.
 							' LEFT JOIN hosts h ON h.hostid=i.hostid '.
 							' LEFT JOIN nodes n ON n.nodeid='.DBid2nodeid('g.graphid').
-						' WHERE g.graphid='.$resourceid);
+						' WHERE g.graphid='.zbx_dbstr($resourceid));
 
 				while($row=DBfetch($result)){
 					$row['node_name'] = isset($row['node_name']) ? '('.$row['node_name'].') ' : '';
@@ -541,7 +540,7 @@
 							' AND h.status='.HOST_STATUS_MONITORED.
 							' AND i.status='.ITEM_STATUS_ACTIVE.
 							' AND '.DBcondition('i.hostid',$available_hosts).
-							' AND i.itemid='.$resourceid);
+							' AND i.itemid='.zbx_dbstr($resourceid));
 
 				while($row=DBfetch($result)){
 					$description_=item_description($row);
@@ -569,7 +568,7 @@
 				$result=DBselect('SELECT n.name as node_name, s.sysmapid,s.name '.
 							' FROM sysmaps s'.
 								' LEFT JOIN nodes n ON n.nodeid='.DBid2nodeid('s.sysmapid').
-							' WHERE s.sysmapid='.$resourceid);
+							' WHERE s.sysmapid='.zbx_dbstr($resourceid));
 
 				while($row=DBfetch($result)){
 					if(!sysmap_accessible($row['sysmapid'],PERM_READ_ONLY)) continue;
@@ -602,7 +601,7 @@
 							' AND h.status='.HOST_STATUS_MONITORED.
 							' AND i.status='.ITEM_STATUS_ACTIVE.
 							' AND '.DBcondition('i.hostid',$available_hosts).
-							' AND i.itemid='.$resourceid);
+							' AND i.itemid='.zbx_dbstr($resourceid));
 
 				while($row=DBfetch($result)){
 					$description_=item_description($row);
@@ -720,7 +719,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)){
 					if(!screen_accessible($row['screenid'], PERM_READ_ONLY)) continue;
@@ -751,7 +750,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'].') ' : '';
@@ -870,11 +869,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();
@@ -1000,7 +999,7 @@
 
 					$sql = 'SELECT g.graphid, g.show_legend as legend, g.show_3d as show3d '.
 							' FROM graphs g '.
-							' WHERE g.graphid='.$resourceid;
+							' WHERE g.graphid='.zbx_dbstr($resourceid);
 					$res = DBselect($sql);
 					if($graph=DBfetch($res)){
 						$graphid = $graph['graphid'];
@@ -1389,7 +1388,7 @@
 				}
 				else if( ($screenitemid!=0) && ($resourcetype==SCREEN_RESOURCE_TRIGGERS_OVERVIEW) ){
 					$hostids = array();
-					$res = DBselect('SELECT DISTINCT hg.hostid FROM hosts_groups hg WHERE hg.groupid='.$resourceid);
+					$res = DBselect('SELECT DISTINCT hg.hostid FROM hosts_groups hg WHERE hg.groupid='.zbx_dbstr($resourceid));
 					while($tmp_host = DBfetch($res)) $hostids[$tmp_host['hostid']] = $tmp_host['hostid'];
 
 					$item = array(get_triggers_overview($hostids,$style));
@@ -1397,7 +1396,7 @@
 				}
 				else if(($screenitemid!=0) && ($resourcetype==SCREEN_RESOURCE_DATA_OVERVIEW)){
 					$hostids = array();
-					$res = DBselect('SELECT DISTINCT hg.hostid FROM hosts_groups hg WHERE hg.groupid='.$resourceid);
+					$res = DBselect('SELECT DISTINCT hg.hostid FROM hosts_groups hg WHERE hg.groupid='.zbx_dbstr($resourceid));
 					while($tmp_host = DBfetch($res)) $hostids[$tmp_host['hostid']] = $tmp_host['hostid'];
 
 					$item = array(get_items_data_overview($hostids,$style));
Index: frontends/php/include/events.inc.php
===================================================================
--- frontends/php/include/events.inc.php	(revision 38884)
+++ frontends/php/include/events.inc.php	(working copy)
@@ -28,14 +28,14 @@
 	}
 
 	function get_event_by_eventid($eventid){
-		$db_events = DBselect('select * from events where eventid='.$eventid);
+		$db_events = DBselect('select * from events where eventid='.zbx_dbstr($eventid));
 		return DBfetch($db_events);
 	}
 
 	function get_tr_event_by_eventid($eventid){
 		$result = DBfetch(DBselect('SELECT e.*,t.triggerid, t.description,t.priority,t.status,t.type '.
 									' 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 '
 									));
@@ -86,7 +86,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);
@@ -97,8 +97,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);
@@ -117,10 +117,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);
@@ -151,8 +151,8 @@
 
 	$sql = 'SELECT e.eventid, 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';
@@ -160,8 +160,8 @@
 
 	$sql = 'SELECT e.eventid, 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';
@@ -171,8 +171,8 @@
 	if($hide_unknown == 0){
 		$sql = 'SELECT e.eventid, 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';
@@ -202,19 +202,19 @@
 	if((TRIGGER_MULT_EVENT_ENABLED == $row['type']) && (TRIGGER_VALUE_TRUE == $row['value'])){
 		$sql = 'SELECT e.eventid, e.value, e.clock '.
 			' FROM events e'.
-			' WHERE e.objectid='.$row['objectid'].
-				' AND e.eventid > '.$row['eventid'].
+			' WHERE e.objectid='.zbx_dbstr($row['objectid']).
+				' AND e.eventid > '.zbx_dbstr($row['eventid']).
 				' 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';
 	}
 	else{
 		$sql = 'SELECT e.eventid, e.value, e.clock '.
 			' FROM events e'.
-			' WHERE e.objectid='.$row['objectid'].
-				' AND e.eventid > '.$row['eventid'].
+			' WHERE e.objectid='.zbx_dbstr($row['objectid']).
+				' AND e.eventid > '.zbx_dbstr($row['eventid']).
 				' AND e.object='.EVENT_OBJECT_TRIGGER.
-				' AND e.value<>'.$row['value'].
+				' AND e.value<>'.zbx_dbstr($row['value']).
 				$sql_cond.
 			' ORDER BY e.object, e.objectid, e.eventid';
 	}
@@ -337,9 +337,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_POPUP_MAX_ROWS);
 
@@ -396,11 +396,11 @@
 	$available_triggers = get_accessible_triggers(PERM_READ_ONLY, array(), PERM_RES_DATA_ARRAY, get_current_nodeid());
 
 	if($hostid > 0){
-		$sql_cond = ' AND h.hostid='.$hostid;
+		$sql_cond = ' AND h.hostid='.zbx_dbstr($hostid);
 	}
 	else if($groupid > 0){
 		$sql_from = ', hosts_groups hg ';
-		$sql_cond = ' AND h.hostid=hg.hostid AND hg.groupid='.$groupid;
+		$sql_cond = ' AND h.hostid=hg.hostid AND hg.groupid='.zbx_dbstr($groupid);
 	}
 	else{
 		$sql_from = '';
Index: frontends/php/include/images.inc.php
===================================================================
--- frontends/php/include/images.inc.php	(revision 38884)
+++ frontends/php/include/images.inc.php	(working copy)
@@ -42,7 +42,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']);
@@ -80,7 +80,7 @@
 				if($DB['TYPE'] == 'POSTGRESQL'){
 					$image = pg_escape_bytea($image);
 					$sql = 'INSERT INTO images (imageid, name, imagetype, image) '.
-									' VALUES ('.$imageid.','.zbx_dbstr($name).','.$imagetype.",'".$image."')";
+									' VALUES ('.$imageid.','.zbx_dbstr($name).','.zbx_dbstr($imagetype).",'".$image."')";
 					return	DBexecute($sql);
 				}
 				else if($DB['TYPE'] == 'ORACLE'){
@@ -88,7 +88,7 @@
 					$lobimage = OCINewDescriptor($DB['DB'], OCI_D_LOB);
 
 					$stid = OCIParse($DB['DB'], 'insert into images (imageid,name,imagetype,image)'.
-						" values ($imageid,".zbx_dbstr($name).','.$imagetype.",EMPTY_BLOB())".
+						" values ($imageid,".zbx_dbstr($name).','.zbx_dbstr($imagetype).",EMPTY_BLOB())".
 						' return image into :image');
 					if(!$stid){
 						$e = ocierror($stid);
@@ -120,7 +120,7 @@
 				}
 
 				return	DBexecute('INSERT INTO images (imageid, name, imagetype, image) '.
-									' VALUES ('.$imageid.','.zbx_dbstr($name).','.$imagetype.','.zbx_dbstr($image).')');
+									' VALUES ('.$imageid.','.zbx_dbstr($name).','.zbx_dbstr($imagetype).','.zbx_dbstr($image).')');
 			}
 			else{
 				error(S_IMAGE_SIZE_MUST_BE_LESS_THAN_MB);
@@ -137,7 +137,7 @@
 // only update parameters
 			return	DBexecute('UPDATE images '.
 							' SET name='.zbx_dbstr($name).',imagetype='.zbx_dbstr($imagetype).
-							' WHERE imageid='.$imageid);
+							' WHERE imageid='.zbx_dbstr($imageid));
 		}
 		else{
 			global $DB;
@@ -153,12 +153,12 @@
 				if($DB['TYPE'] == 'ORACLE'){
 					$result = DBexecute('UPDATE images '.
 									' SET name='.zbx_dbstr($name).',imagetype='.zbx_dbstr($imagetype).
-									' WHERE imageid='.$imageid);
+									' WHERE imageid='.zbx_dbstr($imageid));
 
 					if(!$result) return $result;
 
 
-					if(!$stid = DBselect('SELECT image FROM images WHERE imageid='.$imageid.' FOR UPDATE')){
+					if(!$stid = DBselect('SELECT image FROM images WHERE imageid='.zbx_dbstr($imageid).' FOR UPDATE')){
 					return false;
 					}
 
@@ -174,7 +174,7 @@
 					$image = pg_escape_bytea($image);
 					$sql='UPDATE images '.
 						' SET name='.zbx_dbstr($name).',imagetype='.zbx_dbstr($imagetype).",image='".$image."'".
-						' WHERE imageid='.$imageid;
+						' WHERE imageid='.zbx_dbstr($imageid);
 				return	DBexecute($sql);
 				}
 				else if($DB['TYPE'] == 'SQLITE3'){
@@ -182,7 +182,7 @@
 				}
 
 				$sql='UPDATE images SET name='.zbx_dbstr($name).',imagetype='.zbx_dbstr($imagetype).',image='.zbx_dbstr($image).
-					' WHERE imageid='.$imageid;
+					' WHERE imageid='.zbx_dbstr($imageid);
 
 				return	DBexecute($sql);
 			}
@@ -195,7 +195,7 @@
 
 	function delete_image($imageid){
 		if(!checkImagesToDelete($imageid)) return false;
-		$result = DBexecute('DELETE FROM images WHERE imageid='.$imageid);
+		$result = DBexecute('DELETE FROM images WHERE imageid='.zbx_dbstr($imageid));
 
 	return $result;
 	}
Index: frontends/php/include/maintenances.inc.php
===================================================================
--- frontends/php/include/maintenances.inc.php	(revision 38884)
+++ frontends/php/include/maintenances.inc.php	(working copy)
@@ -40,7 +40,7 @@
 	$sql =	'SELECT DISTINCT m.maintenanceid '.
 			' FROM maintenances m, maintenances_hosts mh, maintenances_groups mg, hosts_groups hg '.
 			' WHERE '.DBcondition('hg.hostid',$available_hosts,true).
-				(!empty($hostid)?' AND hg.hostid='.$hostid:'').
+				(!empty($hostid)?' AND hg.hostid='.zbx_dbstr($hostid):'').
 				' AND ('.
 					'(mh.hostid=hg.hostid AND m.maintenanceid=mh.maintenanceid)'.
 					' OR (mg.groupid=hg.groupid AND m.maintenanceid=mg.maintenanceid))';
@@ -78,7 +78,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;
@@ -104,10 +104,10 @@
 	$result = DBexecute('INSERT INTO maintenances (maintenanceid,name,maintenance_type,description,active_since,active_till) '.
 				' VALUES ('.$maintenanceid.','.
 						zbx_dbstr($maintenance['name']).','.
-						$maintenance['maintenance_type'].','.
+						zbx_dbstr($maintenance['maintenance_type']).','.
 						zbx_dbstr($maintenance['description']).','.
-						$maintenance['active_since'].','.
-						$maintenance['active_till'].')');
+						zbx_dbstr($maintenance['active_since']).','.
+						zbx_dbstr($maintenance['active_till']).')');
 
 return $result?$maintenanceid:false;
 }
@@ -115,7 +115,7 @@
 // function: update_maintenance
 // author: Aly
 function update_maintenance($maintenanceid, $maintenance = array()){
-	$sql = 'SELECT * FROM maintenances WHERE maintenanceid='.$maintenanceid;
+	$sql = 'SELECT * FROM maintenances WHERE maintenanceid='.zbx_dbstr($maintenanceid);
 	if(!$db_maintenance = DBfetch(DBselect($sql))){
 		return false;
 	}
@@ -127,11 +127,11 @@
 
 	$sql = 'UPDATE maintenances SET '.
 				' name='.zbx_dbstr($maintenance['name']).','.
-				' maintenance_type='.$maintenance['maintenance_type'].','.
+				' maintenance_type='.zbx_dbstr($maintenance['maintenance_type']).','.
 				' description='.zbx_dbstr($maintenance['description']).','.
-				' active_since='.$maintenance['active_since'].','.
-				' active_till='.$maintenance['active_till'].
-			' WHERE maintenanceid='.$maintenanceid;
+				' active_since='.zbx_dbstr($maintenance['active_since']).','.
+				' active_till='.zbx_dbstr($maintenance['active_till']).
+			' WHERE maintenanceid='.zbx_dbstr($maintenanceid);
 	$result = DBexecute($sql);
 
 return $result;
@@ -154,13 +154,13 @@
 function save_maintenance_host_links($maintenanceid, $hostids){
 	$result = true;
 
-	DBexecute('DELETE FROM maintenances_hosts WHERE maintenanceid='.$maintenanceid);
+	DBexecute('DELETE FROM maintenances_hosts WHERE maintenanceid='.zbx_dbstr($maintenanceid));
 	foreach($hostids as $id => $hostid)
 	{
 		$maintenance_hostid = get_dbid('maintenances_hosts','maintenance_hostid');
 
 		$result = DBexecute('INSERT INTO maintenances_hosts (maintenance_hostid,maintenanceid,hostid)'.
-				' VALUES ('.$maintenance_hostid.','.$maintenanceid.','.$hostid.')');
+				' VALUES ('.$maintenance_hostid.','.zbx_dbstr($maintenanceid).','.zbx_dbstr($hostid).')');
 	}
 
 return $result;
@@ -169,13 +169,13 @@
 function save_maintenance_group_links($maintenanceid, $groupids){
 	$result = true;
 
-	DBexecute('DELETE FROM maintenances_groups WHERE maintenanceid='.$maintenanceid);
+	DBexecute('DELETE FROM maintenances_groups WHERE maintenanceid='.zbx_dbstr($maintenanceid));
 	foreach($groupids as $id => $groupid)
 	{
 		$maintenance_groupid = get_dbid('maintenances_groups','maintenance_groupid');
 
 		$result = DBexecute('INSERT INTO maintenances_groups (maintenance_groupid,maintenanceid,groupid)'.
-				' VALUES ('.$maintenance_groupid.','.$maintenanceid.','.$groupid.')');
+				' VALUES ('.$maintenance_groupid.','.zbx_dbstr($maintenanceid).','.zbx_dbstr($groupid).')');
 	}
 
 return $result;
@@ -203,14 +203,14 @@
 
 	$result = DBexecute('INSERT INTO timeperiods (timeperiodid,timeperiod_type,every,month,dayofweek,day,start_time,period,start_date) '.
 				' VALUES ('.$timeperiodid.','.
-						$timeperiod['timeperiod_type'].','.
-						$timeperiod['every'].','.
-						$timeperiod['month'].','.
-						$timeperiod['dayofweek'].','.
-						$timeperiod['day'].','.
-						$timeperiod['start_time'].','.
-						$timeperiod['period'].','.
-						$timeperiod['start_date'].')');
+					zbx_dbstr($timeperiod['timeperiod_type']).','.
+					zbx_dbstr($timeperiod['every']).','.
+					zbx_dbstr($timeperiod['month']).','.
+					zbx_dbstr($timeperiod['dayofweek']).','.
+					zbx_dbstr($timeperiod['day']).','.
+					zbx_dbstr($timeperiod['start_time']).','.
+					zbx_dbstr($timeperiod['period']).','.
+					zbx_dbstr($timeperiod['start_date']).')');
 
 return $result?$timeperiodid:false;
 }
@@ -254,12 +254,12 @@
 	zbx_value2array($timeperiodids);
 	$result = true;
 
-	DBexecute('DELETE FROM maintenances_windows WHERE maintenanceid='.$maintenanceid);
+	DBexecute('DELETE FROM maintenances_windows WHERE maintenanceid='.zbx_dbstr($maintenanceid));
 
 	foreach($timeperiodids as $id => $timeperiodid){
 		$maintenance_timeperiodid = get_dbid('maintenances_windows', 'maintenance_timeperiodid');
 		$sql = 'INSERT INTO maintenances_windows (maintenance_timeperiodid,timeperiodid,maintenanceid) '.
-				' VALUES ('.$maintenance_timeperiodid.','.$timeperiodid.','.$maintenanceid.')';
+				' VALUES ('.$maintenance_timeperiodid.','.zbx_dbstr($timeperiodid).','.zbx_dbstr($maintenanceid).')';
 		$result = DBexecute($sql);
 	}
 return $result;
Index: frontends/php/include/media.inc.php
===================================================================
--- frontends/php/include/media.inc.php	(revision 38884)
+++ frontends/php/include/media.inc.php	(working copy)
@@ -53,7 +53,7 @@
 
 	function get_media_by_mediaid($mediaid){
 
-		$sql="select * from media where mediaid=$mediaid";
+		$sql="select * from media where mediaid=".zbx_dbstr($mediaid);
 		$result=DBselect($sql);
 		$row=DBfetch($result);
 		if($row)
@@ -69,18 +69,18 @@
 
 // Delete Media definition by mediatypeid
 	function delete_media_by_mediatypeid($mediatypeid){
-		$sql="delete from media where mediatypeid=$mediatypeid";
+		$sql="delete from media where mediatypeid=".zbx_dbstr($mediatypeid);
 		return	DBexecute($sql);
 	}
 
 // Delete alerts by mediatypeid
 	function delete_alerts_by_mediatypeid($mediatypeid){
-		$sql="delete from alerts where mediatypeid=$mediatypeid";
+		$sql="delete from alerts where mediatypeid=".zbx_dbstr($mediatypeid);
 		return	DBexecute($sql);
 	}
 
 	function get_mediatype_by_mediatypeid($mediatypeid){
-		$sql="select * from media_type where mediatypeid=$mediatypeid";
+		$sql="select * from media_type where mediatypeid=".zbx_dbstr($mediatypeid);
 		$result=DBselect($sql);
 		$row=DBfetch($result);
 		if($row){
@@ -98,7 +98,7 @@
 		delete_alerts_by_mediatypeid($mediatypeid);
 		$mediatype = get_mediatype_by_mediatypeid($mediatypeid);
 
-		$sql='DELETE FROM media_type WHERE mediatypeid='.$mediatypeid;
+		$sql='DELETE FROM media_type WHERE mediatypeid='.zbx_dbstr($mediatypeid);
 
 		if($ret = DBexecute($sql)){
 			add_audit_ext(AUDIT_ACTION_DELETE, AUDIT_RESOURCE_MEDIA_TYPE, $mediatypeid, $mediatype['description'], NULL, NULL, NULL);
@@ -113,7 +113,7 @@
 		$sql='SELECT * '.
 			' FROM media_type '.
 			' WHERE description='.zbx_dbstr($description).
-				' AND mediatypeid<>'.$mediatypeid.
+				' AND mediatypeid<>'.zbx_dbstr($mediatypeid).
 				' AND '.DBin_node('mediatypeid');
 		$result=DBselect($sql);
 		if(DBfetch($result)){
@@ -132,7 +132,7 @@
 					'gsm_modem='.zbx_dbstr($gsm_modem).','.
 					'username='.zbx_dbstr($username).','.
 					'passwd='.zbx_dbstr($password).
-				' WHERE mediatypeid='.$mediatypeid;
+				' WHERE mediatypeid='.zbx_dbstr($mediatypeid);
 			$ret = DBexecute($sql);
 			if($ret){
 				$mediatype_new = get_mediatype_by_mediatypeid($mediatypeid);
@@ -200,7 +200,7 @@
 		$mediaid=get_dbid("media","mediaid");
 
 		$sql='INSERT INTO media (mediaid,userid,mediatypeid,sendto,active,severity,period) '.
-				" VALUES ($mediaid,$userid,".$mediatypeid.','.zbx_dbstr($sendto).','.$active.','.$s.','.zbx_dbstr($period).')';
+				" VALUES ($mediaid,".zbx_dbstr($userid).",".zbx_dbstr($mediatypeid).','.zbx_dbstr($sendto).','.zbx_dbstr($active).','.zbx_dbstr($s).','.zbx_dbstr($period).')';
 
 		if($ret = DBexecute($sql)){
 			$ret = $mediaid;
@@ -225,7 +225,7 @@
 		{
 			$s=$s|pow(2,(int)$severity[$i]);
 		}
-		$sql="update media set userid=$userid, mediatypeid=$mediatypeid, sendto=".zbx_dbstr($sendto).", active=$active,severity=$s,period=".zbx_dbstr($period)." where mediaid=$mediaid";
+		$sql="update media set userid=".zbx_dbstr($userid).", mediatypeid=".zbx_dbstr($mediatypeid).", sendto=".zbx_dbstr($sendto).", active=".zbx_dbstr($active).",severity=".zbx_dbstr($s).",period=".zbx_dbstr($period)." where mediaid=".zbx_dbstr($mediaid);
 		return	DBexecute($sql);
 	}
 
@@ -233,21 +233,21 @@
 
 	function	delete_media($mediaid)
 	{
-		return	DBexecute("delete from media where mediaid=$mediaid");
+		return	DBexecute("delete from media where mediaid=".zbx_dbstr($mediaid));
 	}
 
 	# Activate Media
 
 	function	activate_media($mediaid)
 	{
-		return	DBexecute("update media set active=0 where mediaid=$mediaid");
+		return	DBexecute("update media set active=0 where mediaid=".zbx_dbstr($mediaid));
 	}
 
 	# Disactivate Media
 
 	function	disactivate_media($mediaid)
 	{
-		return	DBexecute("update media set active=1 where mediaid=$mediaid");
+		return	DBexecute("update media set active=1 where mediaid=".zbx_dbstr($mediaid));
 	}
 
 ?>
Index: frontends/php/include/httptest.inc.php
===================================================================
--- frontends/php/include/httptest.inc.php	(revision 38884)
+++ frontends/php/include/httptest.inc.php	(working copy)
@@ -56,14 +56,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.','.zbx_dbstr($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;
 		}
@@ -71,9 +71,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(
@@ -100,12 +100,12 @@
 		foreach($monitored_items as $item){
 			$item_data = DBfetch(DBselect('select i.itemid,i.history,i.trends,i.status,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.status,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(
@@ -165,11 +165,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;
 
 		}
@@ -193,7 +193,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))){
@@ -201,7 +201,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'];
 			}
@@ -219,16 +219,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');
 				}
@@ -240,11 +240,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,
@@ -275,7 +275,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']])){
@@ -301,12 +301,12 @@
 			foreach($monitored_items as $item){
 				$item_data = DBfetch(DBselect('select i.itemid,i.history,i.trends,i.status,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.status,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(
@@ -366,10 +366,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');
 				}
 			}
@@ -403,7 +403,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;
 		}
 
@@ -415,7 +415,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 '.
@@ -452,17 +452,17 @@
 	}
 
 	function activate_httptest($httptestid){
-		return DBexecute('UPDATE httptest SET status='.HTTPTEST_STATUS_ACTIVE.' WHERE httptestid='.$httptestid);
+		return DBexecute('UPDATE httptest SET status='.HTTPTEST_STATUS_ACTIVE.' WHERE httptestid='.zbx_dbstr($httptestid));
 	}
 
 	function disable_httptest($httptestid){
-		return DBexecute('UPDATE httptest SET status='.HTTPTEST_STATUS_DISABLED.' WHERE httptestid='.$httptestid);
+		return DBexecute('UPDATE httptest SET status='.HTTPTEST_STATUS_DISABLED.' WHERE httptestid='.zbx_dbstr($httptestid));
 	}
 
 	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)){
@@ -472,19 +472,19 @@
 	}
 
 	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_httpsteps_by_httptestid($httptestid){
-		return DBselect('select * from httpstep where httptestid='.$httptestid);
+		return DBselect('select * from httpstep where httptestid='.zbx_dbstr($httptestid));
 	}
 
 	function get_httpstep_by_httpstepid($httpstepid){
-		return DBfetch(DBselect('select * from httpstep where httpstepid='.$httpstepid));
+		return DBfetch(DBselect('select * from httpstep where httpstepid='.zbx_dbstr($httpstepid)));
 	}
 
 	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/items.inc.php
===================================================================
--- frontends/php/include/items.inc.php	(revision 38884)
+++ frontends/php/include/items.inc.php	(working copy)
@@ -199,7 +199,7 @@
 //*/
 		$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=DBexecute($sql);
@@ -224,7 +224,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=DBexecute($sql);
@@ -242,7 +242,7 @@
 	function	add_item_to_group($groupid,$item){
 /*	$description,$key,$hostid,$delay,$history,$status,$type,$snmp_community,$snmp_oid,$value_type,$trapper_hosts,$snmp_port,$units,$multiplier,$delta,$snmpv3_securityname,$snmpv3_securitylevel,$snmpv3_authpassphrase,$snmpv3_privpassphrase,$formula,$trends,$logtimefmt,$valuemapid,$delay_flex,$params,$ipmi_sensor,$applications)
 //*/
-		$sql='SELECT hostid FROM hosts_groups WHERE groupid='.$groupid;
+		$sql='SELECT hostid FROM hosts_groups WHERE groupid='.zbx_dbstr($groupid);
 		$result=DBexecute($sql);
 		while($row=DBfetch($result)){
 			$item['hostid'] = $row['hostid'];
@@ -377,7 +377,7 @@
 
 		$sql = 'SELECT itemid,hostid '.
 				' 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){
@@ -402,15 +402,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'].','.
-						$item['delay'].','.$item['history'].','.$item['status'].','.$item['type'].','.
-						zbx_dbstr($item['snmp_community']).','.zbx_dbstr($item['snmp_oid']).','.$item['value_type'].','.$item['data_type'].','.
-						zbx_dbstr($item['trapper_hosts']).','.$item['snmp_port'].','.zbx_dbstr($item['units']).','.$item['multiplier'].','.
-						$item['delta'].','.zbx_dbstr($item['snmpv3_securityname']).','.$item['snmpv3_securitylevel'].','.
+			' VALUES ('.$itemid.','.zbx_dbstr($item['description']).','.zbx_dbstr($item['key_']).','.zbx_dbstr($item['hostid']).','.
+						$item['delay'].','.zbx_dbstr($item['history']).','.zbx_dbstr($item['status']).','.zbx_dbstr($item['type']).','.
+						zbx_dbstr($item['snmp_community']).','.zbx_dbstr($item['snmp_oid']).','.zbx_dbstr($item['value_type']).','.zbx_dbstr($item['data_type']).','.
+						zbx_dbstr($item['trapper_hosts']).','.zbx_dbstr($item['snmp_port']).','.zbx_dbstr($item['units']).','.zbx_dbstr($item['multiplier']).','.
+						zbx_dbstr($item['delta']).','.zbx_dbstr($item['snmpv3_securityname']).','.zbx_dbstr($item['snmpv3_securitylevel']).','.
 						zbx_dbstr($item['snmpv3_authpassphrase']).','.zbx_dbstr($item['snmpv3_privpassphrase']).','.
-						zbx_dbstr($item['formula']).','.$item['trends'].','.zbx_dbstr($item['logtimefmt']).','.$item['valuemapid'].','.
+						zbx_dbstr($item['formula']).','.zbx_dbstr($item['trends']).','.zbx_dbstr($item['logtimefmt']).','.zbx_dbstr($item['valuemapid']).','.
 						zbx_dbstr($item['delay_flex']).','.zbx_dbstr($item['params']).','.
-						zbx_dbstr($item['ipmi_sensor']).','.$item['templateid'].','.$item['authtype'].','.
+						zbx_dbstr($item['ipmi_sensor']).','.zbx_dbstr($item['templateid']).','.zbx_dbstr($item['authtype']).','.
 						zbx_dbstr($item['username']).','.zbx_dbstr($item['password']).','.
 						zbx_dbstr($item['publickey']).','.zbx_dbstr($item['privatekey']).')'
 			);
@@ -422,7 +422,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_']);
@@ -484,11 +484,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){
@@ -570,14 +570,14 @@
 			$item['data_type'] = 0;
 		}
 
-		$db_item = DBfetch(DBselect('SELECT itemid FROM items WHERE hostid='.$item['hostid'].' and itemid<>'.$itemid.' and key_='.zbx_dbstr($item['key_'])));
+		$db_item = DBfetch(DBselect('SELECT itemid FROM items WHERE hostid='.zbx_dbstr($item['hostid']).' and itemid<>'.zbx_dbstr($itemid).' and key_='.zbx_dbstr($item['key_'])));
 		if($db_item && $item['templateid'] == 0){
 			error(S_AN_ITEM_WITH_THE_KEY.SPACE.'['.$item['key_'].']'.SPACE.S_ALREADY_EXISTS_FOR_HOST_SMALL.SPACE.'['.$host['host'].'].'.SPACE.S_THE_KEY_MUST_BE_UNIQUE);
 			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;
 
@@ -612,14 +612,14 @@
 		}
 
 		$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).')');
 			}
 		}
 
@@ -630,37 +630,38 @@
 			'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='.zbx_dbstr($item['snmpv3_authpassphrase']).','.
 				'snmpv3_privpassphrase='.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);
@@ -772,7 +773,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("Item '".$db_item["key_"]."' unlinked");
 				}
 			}
@@ -898,7 +899,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;
 		}
@@ -913,7 +914,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;
@@ -950,7 +951,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);
 
@@ -1043,7 +1044,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
@@ -1318,7 +1319,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"]);
@@ -1361,27 +1362,27 @@
 			foreach($itemids as $id => $itemid){
 				$housekeeperid = get_dbid('housekeeper','housekeeperid');
 				$sql = 'INSERT INTO housekeeper (housekeeperid,tablename,field,value)'.
-							" VALUES ($housekeeperid,'history_text','itemid',$itemid)";
+							" VALUES ($housekeeperid,'history_text','itemid',".zbx_dbstr($itemid).")";
 				DBexecute($sql);
 
 				$housekeeperid = get_dbid('housekeeper','housekeeperid');
 				$sql = 'INSERT INTO housekeeper (housekeeperid,tablename,field,value)'.
-							" VALUES ($housekeeperid,'history_log','itemid',$itemid)";
+							" VALUES ($housekeeperid,'history_log','itemid',".zbx_dbstr($itemid).")";
 				DBexecute($sql);
 
 				$housekeeperid = get_dbid('housekeeper','housekeeperid');
 				$sql = 'INSERT INTO housekeeper (housekeeperid,tablename,field,value)'.
-							" VALUES ($housekeeperid,'history_uint','itemid',$itemid)";
+							" VALUES ($housekeeperid,'history_uint','itemid',".zbx_dbstr($itemid).")";
 				DBexecute($sql);
 
 				$housekeeperid = get_dbid('housekeeper','housekeeperid');
 				$sql = 'INSERT INTO housekeeper (housekeeperid,tablename,field,value)'.
-							" VALUES ($housekeeperid,'history_str','itemid',$itemid)";
+							" VALUES ($housekeeperid,'history_str','itemid',".zbx_dbstr($itemid).")";
 				DBexecute($sql);
 
 				$housekeeperid = get_dbid('housekeeper','housekeeperid');
 				$sql = 'INSERT INTO housekeeper (housekeeperid,tablename,field,value)'.
-							" VALUES ($housekeeperid,'history','itemid',$itemid)";
+							" VALUES ($housekeeperid,'history','itemid',".zbx_dbstr($itemid).")";
 				DBexecute($sql);
 			}
 			return TRUE;
@@ -1407,7 +1408,7 @@
 			foreach($itemids as $id => $itemid){
 				$housekeeperid = get_dbid('housekeeper','housekeeperid');
 				DBexecute('INSERT INTO housekeeper (housekeeperid,tablename,field,value)'.
-					" VALUES ($housekeeperid, 'trends','itemid',$itemid)");
+					" VALUES ($housekeeperid, 'trends','itemid',".zbx_dbstr($itemid).")");
 			}
 			return TRUE;
 		}
@@ -1482,18 +1483,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/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 * from acknowledges where eventid=$eventid");
+	return DBselect("select * from acknowledges where eventid=".zbx_dbstr($eventid));
 }
 
 function add_acknowledge_coment($eventid, $userid, $message){
@@ -43,7 +43,7 @@
 	$acknowledgeid = get_dbid("acknowledges","acknowledgeid");
 
 	$result =  DBexecute("insert into acknowledges (acknowledgeid,userid,eventid,clock,message)".
-		" values ($acknowledgeid,$userid,$eventid,".time().",".zbx_dbstr($message).")");
+		" values ($acknowledgeid,".zbx_dbstr($userid).",".zbx_dbstr($eventid).",".time().",".zbx_dbstr($message).")");
 
 	if(!$result)
 		return $result;
@@ -52,7 +52,7 @@
 }
 
 function set_event_acnowledged($eventid){
-	return DBexecute("update events set acknowledged=1 where eventid=$eventid");
+	return DBexecute("update events set acknowledged=1 where eventid=".zbx_dbstr($eventid));
 }
 
 function make_acktab_by_eventid($eventid){
Index: frontends/php/include/triggers.inc.php
===================================================================
--- frontends/php/include/triggers.inc.php	(revision 38884)
+++ frontends/php/include/triggers.inc.php	(working copy)
@@ -311,7 +311,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;
 
@@ -470,7 +470,7 @@
 	}
 
 	function get_trigger_by_triggerid($triggerid){
-		$sql='select * from triggers where triggerid='.$triggerid;
+		$sql='select * from triggers where triggerid='.zbx_dbstr($triggerid);
 		$result=DBselect($sql);
 		$row=DBfetch($result);
 		if($row){
@@ -491,7 +491,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));
 	}
 
 /*
@@ -509,7 +509,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;
@@ -851,8 +851,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;
@@ -866,7 +866,7 @@
 
 
 		if($result){
-			DBexecute('update triggers set expression='.zbx_dbstr($expression).' where triggerid='.$triggerid);
+			DBexecute('update triggers set expression='.zbx_dbstr($expression).' where triggerid='.zbx_dbstr($triggerid));
 
 			foreach($deps as $id => $triggerid_up){
 				if(!$result2=add_trigger_dependency($triggerid, $triggerid_up)){
@@ -924,13 +924,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 ';
@@ -957,9 +957,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;
@@ -972,7 +972,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'].'"');
@@ -982,7 +982,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(
@@ -991,7 +991,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));
 // copy dependencies
 		// delete_dependencies_by_triggerid($newtriggerid);
 		$deps = replace_template_dependencies(get_trigger_dependencies_by_triggerid($triggerid),$hostid);
@@ -1181,7 +1181,7 @@
 				$state='';
 				$sql = 'SELECT h.host,i.itemid,i.key_,f.function,f.triggerid,f.parameter,i.itemid,i.status'.
 						' 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';
 
@@ -1413,7 +1413,7 @@
 				$functionid = get_dbid('functions','functionid');
 
 				if( !DBexecute('insert into functions (functionid,itemid,triggerid,function,parameter)'.
-					' values ('.$functionid.','.$itemid.','.$triggerid.','.zbx_dbstr($function).','.
+					' values ('.$functionid.','.$itemid.','.zbx_dbstr($triggerid).','.zbx_dbstr($function).','.
 					zbx_dbstr($parameter).')'))
 				{
 					return	null;
@@ -1452,7 +1452,7 @@
 
 		add_event($triggerids,TRIGGER_VALUE_UNKNOWN);
 
-	return DBexecute('UPDATE triggers SET status='.$status.' WHERE '.DBcondition('triggerid',$triggerids));
+	return DBexecute('UPDATE triggers SET status='.zbx_dbstr($status).' WHERE '.DBcondition('triggerid',$triggerids));
 	}
 
 	/*
@@ -1556,12 +1556,12 @@
 							$description = str_replace($macro, $triggerData['lastvalue'], $description);
 						}
 						else{
-							$sql = 'SELECT MAX(clock) as max FROM history_log WHERE itemid='.$triggerData['itemid'];
+							$sql = 'SELECT MAX(clock) as max FROM history_log WHERE itemid='.zbx_dbstr($triggerData['itemid']);
 							$trigger3=DBfetch(DBselect($sql));
 							if($trigger3 && !is_null($trigger3['max'])){
 								$sql = 'SELECT value '.
 										' FROM history_log '.
-										' WHERE itemid='.$triggerData['itemid'].
+										' WHERE itemid='.zbx_dbstr($triggerData['itemid']).
 											' AND clock='.$trigger3['max'];
 								$trigger4=DBfetch(DBselect($sql));
 								$description = str_replace($macro, $trigger4['value'], $description);
@@ -1636,12 +1636,12 @@
 							$description = str_replace($macro, $triggerData['lastvalue'], $description);
 						}
 						else{
-							$sql = 'SELECT MAX(clock) as max FROM history_log WHERE itemid='.$triggerData['itemid'];
+							$sql = 'SELECT MAX(clock) as max FROM history_log WHERE itemid='.zbx_dbstr($triggerData['itemid']);
 							$trigger3=DBfetch(DBselect($sql));
 							if($trigger3 && !is_null($trigger3['max'])){
 								$sql = 'SELECT value '.
 										' FROM history_log '.
-										' WHERE itemid='.$triggerData['itemid'].
+										' WHERE itemid='.zbx_dbstr($triggerData['itemid']).
 											' AND clock='.$trigger3['max'];
 								$trigger4=DBfetch(DBselect($sql));
 								$description = str_replace($macro, $trigger4['value'], $description);
@@ -1756,7 +1756,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);
@@ -1788,7 +1788,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;
 	}
@@ -1814,7 +1814,7 @@
 		foreach($triggerids as $id => $triggerid){
 			$eventid = get_dbid('events','eventid');
 			$result = DBexecute('INSERT INTO events (eventid,source,object,objectid,clock,value) '.
-					' VALUES ('.$eventid.','.EVENT_SOURCE_TRIGGERS.','.EVENT_OBJECT_TRIGGER.','.$triggerid.','.$time.','.$value.')');
+					' VALUES ('.$eventid.','.EVENT_SOURCE_TRIGGERS.','.EVENT_OBJECT_TRIGGER.','.zbx_dbstr($triggerid).','.$time.','.zbx_dbstr($value).')');
 			$events[$eventid] = $eventid;
 		}
 
@@ -2018,13 +2018,13 @@
 		$sql='UPDATE triggers SET ';
 		if(!is_null($expression))	$sql .= ' expression='.zbx_dbstr($expression).',';
 		if(!is_null($description))	$sql .= ' description='.zbx_dbstr($description).',';
-		if(!is_null($type))			$sql .= ' type='.$type.',';
-		if(!is_null($priority))		$sql .= ' priority='.$priority.',';
-		if(!is_null($status))		$sql .= ' status='.$status.',';
+		if(!is_null($type))			$sql .= ' type='.zbx_dbstr($type).',';
+		if(!is_null($priority))		$sql .= ' priority='.zbx_dbstr($priority).',';
+		if(!is_null($status))		$sql .= ' status='.zbx_dbstr($status).',';
 		if(!is_null($comments))		$sql .= ' comments='.zbx_dbstr($comments).',';
 		if(!is_null($url))			$sql .= ' url='.zbx_dbstr($url).',';
-		if(!is_null($templateid))	$sql .= ' templateid='.$templateid.',';
-		$sql .= ' value=2 WHERE triggerid='.$triggerid;
+		if(!is_null($templateid))	$sql .= ' templateid='.zbx_dbstr($templateid).',';
+		$sql .= ' value=2 WHERE triggerid='.zbx_dbstr($triggerid);
 
 		$result = DBexecute($sql);
 
@@ -2058,7 +2058,7 @@
 	}
 
 	function check_right_on_trigger_by_triggerid($permission,$triggerid){
-		$trigger_data = DBfetch(DBselect('select expression from triggers where triggerid='.$triggerid));
+		$trigger_data = DBfetch(DBselect('select expression from triggers where triggerid='.zbx_dbstr($triggerid)));
 
 		if(!$trigger_data) return false;
 
@@ -2088,7 +2088,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'];
 
@@ -2114,11 +2114,11 @@
 
 		$triggerdepid = get_dbid('trigger_depends','triggerdepid');
 		$result=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).")");
 		if(!$result){
 			return	$result;
 		}
-	return DBexecute('UPDATE triggers SET dep_level=dep_level+1 WHERE triggerid='.$triggerid_up);
+	return DBexecute('UPDATE triggers SET dep_level=dep_level+1 WHERE triggerid='.zbx_dbstr($triggerid_up));
 	}
 
 /*
@@ -2139,7 +2139,7 @@
 
 		$sql = 'SELECT DISTINCT t.triggerid, t.templateid '.
 							' 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 '.
 								' AND t.templateid > 0';
@@ -2153,7 +2153,7 @@
 
 		$sql = 'SELECT DISTINCT td.* '.
 				' FROM items i, functions f, triggers t, trigger_depends td '.
-				' WHERE i.hostid='.$hostid.
+				' WHERE i.hostid='.zbx_dbstr($hostid).
 					' AND f.itemid=i.itemid '.
 					' AND t.triggerid=f.triggerid '.
 					' AND ( (td.triggerid_up=t.templateid) OR (td.triggerid_down=t.templateid) )';
@@ -2229,10 +2229,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'];
 			}
@@ -2269,7 +2269,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!!!
@@ -2296,7 +2296,7 @@
 						' OR ('.DBcondition('td.triggerid_up',$triggerids).' AND f.triggerid=td.triggerid_down)) '.
 						' AND i.itemid=f.itemid '.
 						' AND h.hostid=i.hostid '.
-						' AND h.hostid<>'.$templateid.
+						' AND h.hostid<>'.zbx_dbstr($templateid).
 						' AND h.status='.HOST_STATUS_TEMPLATE;
 
 			$db_dephosts = DBselect($sql);
@@ -2701,7 +2701,7 @@
 			$sql = 'SELECT DISTINCT i.itemid, i.description, i.key_, i.value_type '.
 					' FROM items i, functions f '.
 					' WHERE f.itemid=i.itemid '.
-						' AND f.triggerid='.$trhosts[$hostname]['triggerid'];
+						' AND f.triggerid='.zbx_dbstr($trhosts[$hostname]['triggerid']);
 			$db_items = DBselect($sql);
 			while($item_data = DBfetch($db_items)){
 				$description = item_description($item_data);
@@ -2756,7 +2756,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']));
@@ -2778,7 +2778,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']));
@@ -2813,7 +2813,7 @@
 	}
 
 	function get_function_by_functionid($functionid){
-		$result=DBselect('SELECT * FROM functions WHERE functionid='.$functionid);
+		$result=DBselect('SELECT * FROM functions WHERE functionid='.zbx_dbstr($functionid));
 		$row=DBfetch($result);
 		if($row){
 			return	$row;
@@ -2830,9 +2830,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'];
@@ -2842,11 +2842,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));
@@ -2886,10 +2886,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)){
@@ -2973,7 +2973,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);
@@ -3056,7 +3056,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/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'];
