Alert box is not showing inside codeigniter controller -


in controller alert box not working inside if loop.if condition working,only problem alert box,but not showing dialog box.please help. tried many times.

controller erp_c

function tabl() {    $result['query2']=$this->erp_m->getregion();     $this->load->view('head1');             $this->load->view('header3');    $this->load->view('userregionview',$result); }      function userregioninsert($user)         {              if($this->input->post())             $m1=$this->input->post('reg');         //    print_r($m1);die;                $result['query']=$this->erp_m->insertregion($m1,$user);               $result['query2']=$this->erp_m->getregion();         //      print_r($result['query']);die;                   if(($result['query'])>0)                   {            ?>                      <script type=text/javascript>alert("region added");</script>          <?php          }         else         {             ?>                      <script type=text/javascript>             alert("name available");         </script>          <?php                    $this->erp_m->insertregion2($m1,$user);                    }                    redirect('erp_c/tabl');                  }  

model erp_m

  function getregion()       {              $query2=$this->db->get('region3');            return $query2->result();       }        function insertregion($m1,$user)       {            $this->db->where('region',$m1);            $res=$this->db->get('region3');              $num=$res->num_rows();                   return $num;                    }    function insertregion2($m1,$user)         {             $data=array('region'=>$m1,'user'=>$user);             $this->db->insert('region3',$data);          } 

you missing "".

this <script type=text/javascript> should come <script type="text/javascript">

<script type="text/javascript">     alert("region added"); </script>  <script type="text/javascript">     alert("name available"); </script> 

and check empty empty() function

edit 01

    function insertregion($m1)     {         $query = $this->db->query("select * table_name region='$m1' ");//change table name         $result = $query->result_array();         $count = count($result);         return $count;     } 

and instead of using if ( $this->input->post() ) use if(isset($_post['reg']))

so final answer be

    function userregioninsert($user)     {          if(isset($_post['reg']))         {             $m1 = $this->input->post('reg');              $count = $this->erp_m->insertregion($m1);             $result['query2'] = $this->erp_m->getregion();              if ($count==1)             {                 ?>                 <script type="text/javascript">                     alert("region added");                 </script>             <?php             }             else             {                 ?>                 <script type="text/javascript">                     alert("name available");                 </script>                 <?php                 $this->erp_m->insertregion2($m1, $user);             }         }         else         {             redirect('erp_c/tabl');         }                 } 

Comments

Popular posts from this blog

android - Gradle sync Error:Configuration with name 'default' not found -

java - Andrioid studio start fail: Fatal error initializing 'null' -

html - jQuery UI Sortable - Remove placeholder after item is dropped -