Friday, 25 September 2015

Add data to database using simple AJAX

How to Add data to database using simple AJAX

Step 1 : First we will create the form with username and details fields.
Step 2 : Then create ajax code with in same page.
 <script>  
 $(document).ready(function(){  
 $('#ajax-contact-form').submit(function(evt){  
           evt.preventDefault();  
           $.ajax({  
 type: "POST",  
 /*dataType: "json",*/  
 url: "add.php",  
 data: $('#ajax-contact-form').serialize(),  
 success: function(html){  
      if(html==1)  
      {  
           alert("Added successfully");  
           window.location="index.php";  

Thursday, 24 September 2015

Fix the sidebar within a particular space using Jquery

How to Fix the sidebar within a particular space using Jquery

First we create div and give id for div the use the below jquery code.
<script type="text/javascript">  
        $(document).ready(function(){  
             var winheight=$(window).height();  
             var docheight=$(document).height();  
             var footheight=$('#bottom').height();  
             var divheight=$('#fix').height();  
             var vheight=$('#fix').offset().top;  
             //alert(winheight + '--'+docheight +'--'+ footheight);  
             var finalhe=docheight-footheight-divheight-vheight+80;  
             $(window).scroll(function(){  
             if($(this).scrollTop() > 300 && $(this).scrollTop() < finalhe)  
             {  
                  //alert($(this).scrollTop()+'--'+finalhe);  
                     $('#fix').css('position','fixed');  
                     $('#fix').css('top','20px');  
                     $('#fix').css('width','253');  
                     $('#fix ul .full .parent_li .sub-menu').css('z-index','11');  
                }  
                else  
                {  
                     $('#fix').css('position','relative');  
                     $('#fix').css('width','253');  
                     $('#fix').css('top','0px');  
                }  
                });  
        });  
   </script>  
Example screenshot.

Wednesday, 23 September 2015

Update the data with images to database using Codeigniter

How to update the data with images to database using Codeigniter

Step 1 : In view folder create edit_project.php file and copy the following data.
 <form action="<?php echo site_path?>admin/edit_update/<?php echo $edit1['list_id'];?>" method="post" enctype="multipart/form-data">  
         <input type="hidden" name="<?php echo $this->security->get_csrf_token_name(); ?>" id="csrf_token" value="<?php echo $this->security->get_csrf_hash(); ?>"/>  
           <div class="row">  
                <div class="col-lg-12">  
                     <div class="col-lg-2"><label for="text">Title</label></div>  
                     <input type="text" class="text" id="title" name="title" placeholder="Title" value="<?php echo $edit1['title'];?>"/>  
                </div>  
           </div>  
           <div class="row">  
                <div class="col-lg-12">  
                     <div class="col-lg-2"><label for="text">Category</label></div>  
                     <!--<input type="text" class="text" id="categoty" name="category" placeholder="Category" value="<?php echo $edit1['category'];?>"/>-->  
                     <select class="col-lg-3 " multiple="multiple" id="categoty" name="category[]" style="margin-bottom: 10px;">  
                     <?php   
                     foreach($cate as $opt)  
                     {  

Create Secure Login with Session Login in using Codeigniter

How to create Secure Login with Session Login in using Codeigniter

Step 1 : In view folder create login page and copy the below code.
 <div class="form-box" id="login-box">  
       <div class="header">Sign In</div>  
       <form action="" method="post" id="frm">  
       <input type="hidden" name="<?php echo $this->security->get_csrf_token_name(); ?>" id="csrf_token" value="<?php echo $this->security->get_csrf_hash(); ?>"/>  
         <div class="body bg-gray">  
         <?php if($message!='')  
                     {  
                          ?>  
                          <div class="alert alert-danger alert-dismissable" id="alert">  
                     <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>  
                     <b>Alert!</b> Username or Password not match  
                   </div>  
                          <?php   
                     }?>  
           <div class="form-group">  
             <input type="text" name="userid" class="form-control" id="name" placeholder="User ID" value="<?php echo $username;?>"/>  
           </div>  
           <div class="form-group">  
             <input type="password" name="password" class="form-control" id="email" placeholder="Password"/>  
           </div>       
         </div>  
         <div class="footer">             

Tuesday, 22 September 2015

Form Validation using Codigniter

How to Form Validation using Codigniter

Step 1 : just copy and paste the below content.
 $this->load->library('form_validation');  
           if ($this->form_validation->run('add_project') == FALSE)  
           {  
             echo validation_errors();  
           }  
           else  
           {  

Step 2 : Create form_validation.php on config folder and copy the below content.