Showing posts with label Codeigniter. Show all posts
Showing posts with label Codeigniter. Show all posts

Tuesday, September 20, 2016

Case Sensitive login in codeigniter

7:48:00 PM 0
How to implement case sensitive user login in codeigniter ?. This is the topic we are gonna to see today. Implementing login with case sensitive option in codeigniter is very easy. That is, we need to give 'LIKE BINARY' after the database field name in model query.

Case Sensitive login in codeigniter
Case Sensitive login in codeigniter

Lets see the example codeigniter controller and model codes to that are used to get case sensitive user data from database.

Controller Code:


<?php

function login_controller()
{
 $email = $this->input->post('email');
 $password = $this->input->post('password');
 
 if($email && $password)
 {
  $query = $this->user_model->login_model($email,$password);
  if($query)
  {
   echo "Login Success..";
  }
  else
  {
   echo "Login Failed..";
  }
 }
}
?>

Model Code:

function login_model($email,$password)
{
 $this->db->select('*');
 $this->db->from("user_account");
 $this->db->where("email",$email);
 $this->db->where("password like binary",$password);
 $query = $this->db->get();
 if($query->num_rows() > 0)
 {
  return $query->result();
 }
return false;
}

The main thing used here is $this->db->where("password like binary",$password);

Search Keywords
  • Case sensitive password check in codeigniter
  • Codeigniter case sensitive query
  • Codeigniter Binary query

Wednesday, July 13, 2016

How to send emails with HTML page/template in codeigniter

5:07:00 PM 0
Codeigniter allows programmers to send HTML file as an email. This helps to send emails using codeigniter in a good formatted and stylish method. Below we have given codes to send HTML pages along with email in codeigniter. Just run it and comment your view below.
codeigniter send email using html template
codeigniter send email using html template

How send emails in codeignter using email templates?

Controller:

public function test_email()
{
        $this->email->set_mailtype("html");
 $this->email->from('noreply@w3schools100.in', 'W3Schools100');
 $this->email->to('receiver@gmail.com');
 $this->email->subject('Subject');
     
 $mail_data['subject'] = 'Email Subject';
 $mail_data['description'] = "Email body contents..Here you can use HTML tables to format your data..And use \n to print date in a new line"

 $message = $this->load->view('email_page', $mail_data, true);
 $this->email->message($message);
 $this->email->send();
} 
View: -> email_page.php

<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"></link>
  <style>
    /* Remove the navbar's default rounded borders and increase the bottom margin */ 
    .navbar {
      margin-bottom: 50px;
      border-radius: 0;
    }
    
    /* Remove the jumbotron's default bottom margin */ 
     .jumbotron {
      margin-bottom: 0;
    }
   
    /* Add a gray background color and some padding to the footer */
    footer {
    background-color: #37454D;
    color:#fff;
      padding: 10px;
    }
  </style>

  <div style="background-color:lightgrey" class="text-center">
  <!-- Give full URL -->
  <img src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgx53RKF84Qif07L__NTVulVu26pHAP9ZSK4wrLupufXv_1rhtzzfjJOFA79ZiM-dLoe6HRtY2gFl9v5UkKJ9UlynyLJTwmRlGBG6PfyJH-O4qoYc2xlp5vCTFeUQoTrv2kYDuv6LXovUNZ/s1600/SB100+copy.png" class="img-responsive" alt="StudentsBlog100" title="Studentsblog100"/>
  </div>

<div class="container">    
  <div class="row">
    <div class="col-sm-12">
     <h3 style="font-weight:bold"><?php if(isset($subject)) { echo $subject; }?></h3>
     <p><?php if(isset($description)) { echo $description; }?></p>
    </div>
  </div>
</div>

<footer class="container-fluid text-center">
  © W3schools100
</footer>
codeigniter send email using html template

  • codeigniter send email html format
  • mail codeigniter 

Monday, April 11, 2016

How to use or_like and where condition in codeigniter query builder

6:49:00 PM 0
As we know, codeigniter query builder is one of the easiest method to create database queries. But in some complex situations it is not giving exact results. If codeigniter got upgraded, this type of errors will be solved, but it was not upgraded for many years. Anyhow today we are going to see about "How to use or_like and where condition in codeigniter"
or_like and where condition in codeigniter
or_like and where condition in codeigniter

or_like and where condition in codeigniter

Table name : items
idNameTypeCountry
1BananaFruitIndia
2CarrotVegetablePakistan
3AppleFruitUSA
4TomatoVegetableUAE
5OrangeFruitIran
6cucumberVegetableIndia

Consider above table "items". Now you need to search a data from name and country fields, where type =  Fruit. In this case use following code to get exact result from codeigniter.

public function search_items($search_keyword="") {
    $this->db->select('*');
    $this->db->from('items');
    $where = "type = 'Fruit' AND (name LIKE '%$search_keyword%' OR country LIKE '%$search_keyword%')";
    $this->db->where($where);
    $query = $this->db->get();
    if($query->num_rows() > 0) {
        return $query->result();
    }
    return false;
}
Try this and if you have any doubts or any alternative solutions, please comment below. Thank you - W3schools100 Team

Tuesday, April 5, 2016

Codeigniter godaddy hosting error - No input file specified.

6:42:00 PM 0
Usually while developing any php applications using codeigniter framework, developers used to remove index.php from the codeigniter default url by using .htaccess file. And it will work perfectly in local machine. And after uploading all the codeigniter files in godaddy server, some times it wont work properly and it shows and error "No input file specified." To avoid this type of errors, we have added a htaccess file. Just check it and comment below.
Codeigniter godaddy hosting error - No input file specified
Codeigniter godaddy hosting error - No input file specified

How to overcome "No input file specified." godaddy codeigniter error ?

Here we have a solution,

Step 1
  1. Create a file in codeigniter main (root) folder.
  2. Copy paste below given codes
  3. Finally save it as .htaccess (without any name in front of .)
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]

Step 2
  1. Open application->config->config.php
  2. Find " $config['index_page'] " and " $config['uri_protocol'] " code from the config.php file and give the value as given below.
$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';

That's all, now your codeigniter application will run perfectly with godaddy hosting. If you have any queries, please comment below. We will help you as soon as possible.

Search tags:
codeigniter godaddy remove index php

codeigniter htaccess remove index php godaddy
codeigniter htaccess remove index.php not working
no input file specified codeigniter godaddy
no input file specified codeigniter htaccess
codeigniter mod_rewrite no input file specified

Thursday, March 24, 2016

Joining two tables in codeigniter query

6:52:00 PM 1

How to join two tables in codeigniter ?

Codeigniter table joining queries are used to join two database tables. Most of the php web developers know to join mysql database tables using core php but not by using codeigniter query builder. So, today we are going to discuss about joining two tables in codeigniter with examples.
How to join two tables in codeigniter
Codeigniter table join

Consider two database tables 
1)  students_account - To store students details.
2)  school_list - To store school details.

Table 1 : students_account
idstudent_nameschool_id
1Eshin3
2Jozer1
3Jacinth2
Table 2 : school_list
idschool_name
1StudentsBlog100
2W3schools100
3Sample School

Model

function test_model($student_id)
{
     $this->db->select('students_account.*,school_list.school_name');
     $this->db->from("students_account");
     $this->db->join('school_list', 'students_account.school_id = school_list.id', 'left');
     $this->db->where("students_account.id",$student_id);
     $query=$this->db->get();
          if($query->num_rows() > 0)
          {
          return $query->result();
          }
     return false;
}

Controller

public function test_controller() 
{
     $student_id = 2;
  
     $query = $this->model_name->test_model($student_id);  
          if($query)
          {
               echo "<pre>";
               print_r($query);
               echo "</pre>";
          }
          else
          {
               echo "problem in getting student's details";
          }
 }

Test by using above sample codes.. if you have any doubts or any mistakes in the codes given above, please let me know by commenting below.. Thank you, W3schools100 team