警报框未显示在codeigniter控制器内

时间:2015-07-11 04:06:59

标签: codeigniter

如果loop.if条件正常工作,在此控制器警报框内部不起作用,只有警告框出现问题,但它没有显示对话框。请帮助。我试了很多次。

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 already added");</script>

        <?php

        }
        else
        {

           ?>
                     <script type=text/javascript>
            alert("Name Available");
        </script>

        <?php

                  $this->erp_m->insertregion2($m1,$user);

                  }

                  redirect('Erp_c/tabl');

                } 

模型     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);

        }

3 个答案:

答案 0 :(得分:1)

""您错过了。

<script type=text/javascript>应该如下<script type="text/javascript">

<script type="text/javascript">
    alert("Region already added");
</script>

<script type="text/javascript">
    alert("Name Available");
</script>

使用empty()函数

检查为空

修改01

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

而非使用此if ( $this->input->post() )使用if(isset($_POST['reg']))

所以你的最终答案将是

    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 already added");
                </script>
            <?php
            }
            else
            {
                ?>
                <script type="text/javascript">
                    alert("Name Available");
                </script>
                <?php
                $this->erp_m->insertregion2($m1, $user);
            }
        }
        else
        {
            redirect('Erp_c/tabl');
        }           

    }

答案 1 :(得分:1)

e.g。

echo "<script>alert('This card was not approved, Thanks.');</script>";

你也可以在echo

中识别PHP值

答案 2 :(得分:0)

echo '<script>alert("Region already added");</script>';

试试这个