php - Lead Save Database Error In SuiteCRM -


i've created logic hook within leads module save field in database. problem when save lead first displays duplicate message:

database failure error check suitecrm logs.

if comment out code lead saved.

logichook:

<?php  class leaddata {     public function leadsavedata(&$bean, $events, $arguments)     {         $stateid = $bean->state_c;          if ($stateid != "") {             $beanst_state = beanfactory::getbean('s1_state', $stateid);              $statename = $beanst_state->name;             $bean->resstate_c = $statename;         } else {             $bean->resstate_c = "punjab";         }          if (!empty($bean->mediatype_c)) {             $mediatype = $bean->mediatype_c;             $callstatus = $bean->callstatus_c; //for follow             if ($mediatype == 'selectmedia' && $mediatype != '') {                 $bean->refrence_c = 'null';             } else if ($mediatype == 'refrence') {                 $bean->eventname_c = 'null';             } else {                 $bean->mediatype_c = 'null';                 $bean->refrence_c = 'null';                 $bean->eventname_c = 'null';             }              if ($callstatus != 'followup') {                 $bean->calllater_c = '0000-00-00 00:00:00';             }             $bean->save();         }     } } 

please follow these steps in code make error correct or working. hope helps you.

<?php  /*  * change license header, choose license headers in project properties.  * change template file, choose tools | templates  * , open template in editor.  */  if (!defined('sugarentry') || !sugarentry)     die('not valid entry point');  class saveextradata_logic_hooks_class {     static $already_ran = false;      function saveextradata_after_save_method(&$bean, $events, $arguments)     {         global $db;          if (self::$already_ran == true) return;         self::$already_ran = true;          $lead_id = $bean->id;          $stateid = $_post['state_c'];         $sql = "select name s1_state id='$stateid'";         $query = $db->query($sql);         $result = $db->fetchbyassoc($query);         $statename = $result[name];          if ($stateid != "") {             $statename;         } else {             $statename = "punjab";         }         if (!empty($_post['mediatype_c'])) {             $mediatype = $_post['mediatype_c'];              if ($mediatype == 'selectmedia' && $mediatype != '') {                 $mediatype = 'selectmedia';                 $reference = 'null';                 $eventname = $_post['eventname_c'];             } else if ($mediatype == 'refrence') {                 $mediatype = 'refrence';                 $reference = $_post['refrence_c'];                 $eventname = 'null';             } else {                 $mediatype = 'null';                 $reference = 'null';                 $eventname = 'null';             }         }          $callstatus = $_post['callstatus_c'];//for follow         if ($callstatus != 'followup') {             $calllater = '0000-00-00 00:00:00';         }          /*$bean->eventname_c = $eventname;         $bean->refrence_c = $reference;         $bean->mediatype_c = $mediatype_c;         $bean->calllater_c = $calllater;         $bean->resstate_c = $statename;         $bean->save();*/          $leadupdate = "update leads_cstm set resstate_c='$statename',eventname_c='$eventname',refrence_c='$reference',mediatype_c='$mediatype',calllater_c='$calllater' id_c = '$lead_id'";         $resultproductmasterdetail = $db->query($leadupdate);     } } 

Comments