20 January 2021

How to use ajax in Codeigniter?

 Use ajax in Codeigniter


Paste in View

<script>
$(document).ready(function(){
$(".ajax_bt").click(function(e) {
e.preventDefault();  
    var person = $('#person').val();
    var phone = $('#phone').val();
    var email = $('#email').val();
    var password = $('#password').val();
//alert(person+''+''+phone+''+email+''+password);
    $.ajax({
        url: "<?php echo base_url('index.php/Welcome/insert_data_with_ajax'); ?>",
        data: {
'person':person,
'phone':phone,
'email':email,
'password':password
}, // change this to send js object
        type: "post",
        success: function(data){
           //document.write(data); just do not use document.write
           console.log(data);
        }
      });
});
});
</script>

Paste in Controller



class Welcome extends CI_Controller {

 public function __construct()
    {
        parent::__construct();
        
        $this->load->library('session');
        $this->load->helper('html');
        $this->load->helper('url');
        $this->load->helper('form');
        $this->load->helper('file');
        $this->load->library('form_validation');
      
        $this->load->model('Customer_model');

       
    }
 

public function insert_data_with_ajax() {
echo $person = $this->input->post('person');
echo 'jassi';
//$data['main_content']='ajax';
//$this->load->view('template',$data);
}


}

How to upload file in codeigniter?

Upload file in Codeigniter?


Paste this code in controller

if($this->input->post('upload_file'))

{

$config['upload_path']          = 'uploads';

                $config['allowed_types']        = 'gif|jpg|png';

               // $config['max_size']             = 100;

               // $config['max_width']            = 1024;

               // $config['max_height']           = 768;


                $this->load->library('upload', $config);

// $upload_data = $this->upload->data('file_name'); 

                if ( ! $this->upload->do_upload('files'))

                {

                        $error = array('error' => $this->upload->display_errors());


                        //$this->load->view('upload', $error);

echo 'FIle Error';

                }

                else

                {

                         $data = array('upload_data' => $this->upload->data());


                       // $this->load->view('upload', $data);

echo 'FIle Uploaded Successfully';

$upload_name = $this->upload->data('file_name');

                } 

}

Paste this code in View

<div class="user_update_form">

<form method="post" action="" enctype="multipart/form-data" />

<?php echo validation_errors(); ?>  

<?php //echo $error; ?>  

<?php echo form_open_multipart('upload/do_upload');?>

<h1 class="register_lable">Upload Files</h1>

<label>Files</label>

<input type="file" class="input_field" name="files" value="">

<input type="submit" name="upload_file" class="upload_file" value="Update">


</form>

</div>

19 January 2021

How to delete data from database in MySql in codeigniter?

Delete data from database in MySql in codeigniter 


if($this->input->post('delete_user'))

{

$user_id = $this->input->post('user_id');

    $this -> db -> where('ID', $user_id);

$this -> db -> delete('login_form');

redirect(dashboard);

}

How to fetch data from Database in Codeigniter?

Fetch data from Database in Codeigniter



$query = $this->db->get('login_form');
foreach ($query->result() as $row)
{
        echo $row->ID.'<br>';
        echo $row->name.'<br>';
        echo $row->phone.'<br>';
        echo $row->email.'<br>';
        echo $row->password.'<br><hr>';
}

How to insert data into database in MySql in Codeigniter?

 Insert data into the database in MySql in Codeigniter


if($this->input->post('register')){
$name=$this->input->post('person');
$phone=$this->input->post('phone');
$email=$this->input->post('email');
$password=$this->input->post('password');
$data = array(
        'name' => $name,
        'phone' => $phone,
        'email ' => $email,
        'password ' => $password
);
$this->db->insert('login_form', $data);
if($this->db->affected_rows() > 0){
 
echo 'Data inserted successfull';
 
}else{
 
  echo 'Data Not inserted';
}
}

How to Create table into Database in MySQL in Codeigniter?

Create table into Database in MySQL in Codeigniter



if ($this->db->table_exists('members'))
{
  // table exists some code run query
}
else{
 

   
$this->load->dbforge();

// define table fields
$fields = array(
  'memid' => array(
    'type' => 'INT',
    'constraint' => 9,
    'unsigned' => TRUE,
    'auto_increment' => TRUE
  ),
  'firstname' => array(
    'type' => 'VARCHAR',
    'constraint' => 30
  ),
  'lastname' => array(
    'type' => 'VARCHAR',
    'constraint' => 30
  ),
  'email' => array(
    'type' => 'VARCHAR',
    'constraint' => 60,
    'unique' => TRUE
  ),
  'password' => array(
    'type' => 'VARCHAR',
    'constraint' => 40
  )
 );

$this->dbforge->add_field($fields);

// define primary key
$this->dbforge->add_key('memid', TRUE);

// create table
$this->dbforge->create_table('Members');

}

17 December 2020

How to Make Textarea Auto Resize using Javascript?

Make Textarea Auto Resize using Javascript.


<!DOCTYPE html>

<html>

<head>

    <title>Textarea Auto Height</title>

    <script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>

</head>

<body>

  

<h1>Textarea Auto Height</h1>


<textarea id="resize" style="width: 360px;"></textarea>

   

<script type="text/javascript">

    $('#resize').on('input', function () { 

        this.style.height = 'auto'; 

  

        this.style.height = (this.scrollHeight) + 'px'; 

    }); 

</script>

  

</body>

</html> 

How to create video slider with cuncks of videos without download all videos?

 Create video slider with cuncks of videos without download all videos function custom_video_slider_shortcode() { $slider_id = 'vide...