Seach

wordpress as webservice

dowload and install
https://wordpress.org/plugins/json-api/
goto plugin->json api ->controller create gallery.php

<?php
/*
Controller name: Gallery
Controller description: Retrieve gallary posts
*/
class JSON_API_Gallery_Controller {

 function gallery_posts()
 {
  $args=array
  (
  "post_type"=>"gallery",
  "post_status"=>"publish",
  "orderby"=>"ID"
  );
  $posts=get_posts($args);
  $json=array();
if(count($posts)!=0)
{
$json['status']=array('ok');
 
  foreach($posts as $key=>$record)
  {
  $youtube=get_post_meta($record->ID,'youtube',true);
$json["result"][]=array("title"=>$record->post_title,'content'=>$record->post_content,'url'=>$youtube);
  }
  return $json;
  }
  else
  {
  return $json['status']=array('failed');;
  }
 
 
 }

}
this fetch gallery named post data
jquery for fetch the service

 function gallery_load()
{
    $.ajax(
            {
                url: "http://faithsolution.byethost17.com.in/?json=gallery.gallery_posts",
        type: "POST",
        dataType: "jsonp",
        headers: {"'Access-Control-Allow-Origin": "*"},
        beforeSend: function(xhr) {
        }, complete: function(jqXHR, textStatus) {
        }, success: function(data)
        {
            if (data.status == "ok")
            {
                for (i = 0; i < Object.keys(data.result).length; i++)
                {
                   
                }
            }
            else
            {
            }
        }, error: function(jr, textstatus)
        {
            console.log(textstatus);
        }});
}



create a custom metabox in wordpress

https://www.dropbox.com/s/76xabzzqqzoeh2c/sample.php?dl=0
//additional info reffer https://developer.wordpress.org/plugins/metadata/creating-custom-meta-boxes/
function create_metabox_from($post)
{
    $data=get_post_meta( $post->ID,"message");//receiving saved data 
   
    ?>

<input type="text" name="message" id="message" class="widefat" value="<?php echo $data[0];?>">


<?php

}
function create_metabox()
{
    $screen=array("Samples");//it is the post which this meta box need to be apperare
    foreach($screen as $key)
    {
        add_meta_box("sample_metabox","message","create_metabox_from",$screen,"");
    }
   
}
add_action("add_meta_boxes","create_metabox");//creating metabox
add_action( 'save_post', 'save_data' );//saving metabox data
function save_data($post_id)
{
   
    if(array_key_exists("message",$_POST))
    {
        update_post_meta($post_id,"message",$_POST['message']);
    }
}

custom post type in wordpress

code link- https://www.dropbox.com/s/76xabzzqqzoeh2c/sample.php?dl=0
*
 * create a folder named sample under the plugin directory in wordpress wp-content/plugins/ and put the sample.php to it 100% working
 */

<?php
/*
 * Plugin Name:Sample
 * Description:Test purpose
 * Plugin URI:http://hhiitthhiinn.blogspot.com
 * Author:Hithin chandran
 * Version:1.0
 * AUTHOR URI:http://hhiitthhiinn.blogspot.com
 */


function my_custom_post_product() {
  $labels = array(
    'name'               => _x( 'Samples', 'post type general name' ),
    'singular_name'      => _x( 'Sample', 'post type singular name' ),
    'add_new'            => _x( 'Add New', 'Sample' ),
    'add_new_item'       => __( 'Add New Sample ' ),
    'edit_item'          => __( 'Edit Sample' ),
    'new_item'           => __( 'New Sample' ),
    'all_items'          => __( 'All Samples' ),
    'view_item'          => __( 'View samples' ),
    'search_items'       => __( 'Search Samples' ),
    'not_found'          => __( 'No samples found' ),
    'not_found_in_trash' => __( 'No samples found in the Trash' ),
    'parent_item_colon'  => '',
    'menu_name'          => 'Samples'
  );//label settings
 
  $args = array(
    'labels'        => $labels,
    'description'   => 'Holds our Samples and sample specific data',
    'public'        => true,
    'menu_position' => 5,
    'supports'      => array( 'title', 'editor', 'thumbnail', 'excerpt', 'comments','custom-fields','trackbacks',"page-attributes","post-formats" ),
    'has_archive'   => true,
      "slug"=>"sample",
      "show_in_admin_bar"=>true,
      "menu_icon"=>"dashicons-smiley",
      "can_export"=>TRUE
  );//custom post type attributes
  register_post_type( 'product', $args );//used to register a post type 
}
add_action( 'init', 'my_custom_post_product' );//adding the post type
//visit https://codex.wordpress.org/Function_Reference/register_post_type for more information


pagination example in codeigniter

view page

<div id="item">
LIST
</div>
<table >
<th>Product</th>
<th>Quantity</th>
<th>Price</th>
<th>Stock</th>
<th>Image</th>
<th>Action</th>
<?php
if(isset($result))
{
foreach ($result as $data)
{
?>
<tr>
<td>
    <input type="text" name="name" value="<?php echo $data['name'];?>">
</td>
<td>
    <input type="text" name="qty" value="<?php echo $data['qty'];?>" style="width: 40px;">

</td>
<td>
    <input type="text" name="price" value="<?php echo $data['price'];?>" style="width: 80px;">
</td>
<td>
        <input type="text" name="price" value="<?php echo $data['stock'];?>" style="width: 40px;">


</td>
<td>
    <img src="<?php echo base_url().''.$data['image'];?>" width="70" height="100" title="Picture cannot be changed">
</td>
<td>
    <a href="<?php echo $data['id'];?>" id="edit"  ><img src="http://localhost/backery/assets/images/edit.jpg" height="20" width="20"></a>
    &nbsp;&nbsp;
    <a href="<?php echo $data['id'];?>" id="delete"  ><img src="http://localhost/backery/assets/images/delete.jpg" height="20" width="20"></a>
   
</td>
</tr>
<?php
}} ?>
</table>
<div id="link">
<?php echo $link;?>
</div>

controller

public function home()
{
$this->session_alive();
$total=$this->admin_model->count();
$config['total_rows']=$total;
$config['per_page']=2;
$config['base_url']=  site_url().'/admin/home/';
$data['result']=$this->admin_model->list_items(2,$this->uri->segment(3));
if(count($data)>=1)
{
$this->pagination->initialize($config);
$data['link']=$this->pagination->create_links();

$this->load->view('home',$data);
}
else
{
$this->load->view('home');
}
}

model

//used to paginate products
public function list_items($limit,$segment)
{
    $query=$this->db->get('product',$limit,$segment);
    return $query->result_array();
}
//used to find the total
public function count()
{
    return $this->db->count_all('product');
}

how to create a global variable that can be accessed in any view page in codeigniter

1)create a class in application/library folder
2)create a php file to set data to library
3)in autoload.php call the library

Globals.php//in application/library
<?php
class Globals {

// Pass array as an argument to constructor function
public function __construct($config = array()) {

// Create associative array from the passed array
foreach ($config as $key => $value) {
$data[$key] = $value;
}

// Make instance of CodeIgniter to use its resources
$CI = & get_instance();

// Load data into CodeIgniter
$CI->load->vars($data);
}

}

?>

Globals.php// in application/config /

$config['name']='hithin';

demo.php//controller
<?php
defined('BASEPATH') OR EXIT('Dirrect access not allowed');
class Demo extends CI_Controller
{
    public function __construct() {
        parent::__construct();
       
    }
    public function index()
    {
        $this->load->view('demo_view');
    }
}

demo_view.php //view
<?php
echo $name;

simple money payment using paypal api using codeigniter

create a paypal account
 we use paypal.com to original sits for development purpose we use sandbox.paypal account for testing
for reference  of integrating paypal reffer developer.paypal.com documentation and dashbord

controller

<?php
defined('BASEPATH') OR EXIT('Dirrect access not allowed');
class Pay extends CI_Controller
{
    public function __construct() {
        parent::__construct();
    }
    public function index()
    {
        $data['settings']=array('id'=>'your sandboxpaypal id  //mine is sellerhithn@gmail.com','url'=>'https://www.sandbox.paypal.com/cgi-bin/webscr');//test url  for testing provided by paypal orignal is http://www.paypal.com
        $this->load->view('pay_view',$data);
    }
    public function success()
    {
        $this->load->view('success_view');
       
       
    }
    public function failer()
    {
        echo 'problem occured';
    }
}

view
 //to know more options  visit https://developer.paypal.com/webapps/developer/docs/classic/paypal-payments-standard/integration-guide/formbasics/
 
 <form method="post" action="<?php echo $settings['url'];?>">
    <input type='hidden' name='cmd' value='_xclick'>
    <input type="hidden" name="address_override" value="1">
    <input type="hidden" name="first_name" value="hithin chandran">


    <input type="hidden" name="business" value="<?php echo $settings['id'];?>">
    <input type='hidden' name='item_name' value='Exam fee'>
    <input type='hidden' name='item_name' value='<?php echo rand(1,10000);?>'>
    <input type='hidden' name='amount' value='1000'>
    <input type='hidden' name='no_shipping' value='1'>
    <input type='hidden' name='currency_code' value='USD'>
    <input type='hidden' name='handling' value='0'>
    <input type='hidden' name='cancel_return' value="<?php echo site_url('pay/failer'); ?>">
    <input type='hidden' name='return' value="<?php echo site_url('pay/success'); ?>">

    <input type="image" src="https://www.sandbox.paypal.com/en_US/i/btn/btn_buynowCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
    <img alt="" border="0" src="https://www.sandbox.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1">

                   
</form>
<div>
  
</div>


how to populate a dropdown list in codeigniter using json,jquery,ajax

view

<head>
    <script src="<?php echo base_url().'js/jquery.js';?>"></script>
</head>
<form method="post" >
    <select id="select">
        
    </select>
</form>

<script>
   $(document).ready(function(e){
       $.ajax({
           dataType: 'json',
           url: "json_",
           type: 'POST',
           processData: false,
           cache: false,error: function (jqXHR, textStatus, errorThrown) {
                        alert('error occured');
                    },
           success: function (data, textStatus, jqXHR)
           {
    
//           $.each(data,function(key, value){
//             $('<option />', {value: value
//                         .actor_id, text: value.first_name}).appendTo("#select");
//        });
    
$.each(data,function(key,value)
{
    $('</option>',{value:value.actor_id,text:value.first_name}).appendTo("#select");
});}            
       });
   });
</script>

controller
public function json_()
    {
        $this->load->model('json_model');
        $tmp=$this->json_model->fetch();
        echo json_encode($tmp);
        
    }

model

public function fetch()
    {
        $this->db->select('actor_id,first_name');
        $this->db->from('actor');
        $data=$this->db->get();
        return $data->result_array();
    }




how to use session class in codeigniter login demo

Controller emp.php

<?php
defined('BASEPATH') OR EXIT('Dirrect Access Not Allowed');
class Emp extends CI_Controller
{
    public function __construct()
    {
        parent::__construct();
        $this->load->library('session'); //used to load session library
        $this->load->helper('url','form');
    }
    public function index()
    {
        $this->load->view('login');
    }
    public function login()
    {
     $data=array('email'=>$this->input->post('userid'),'password'=>$this->input->post('password'));
     $this->load->model('login_user');
     $record=$this->login_user->entry($data);
     $this->session->set_userdata(array('id'=>$record->id,'email'=>$record->email));
     $this->load->view('userdata');
    }
}

Model login_user.php

<?php
defined('BASEPATH') OR EXIT('Dirrect Script Not Allowed');
class Login_user extends CI_Model
{
    public function __construct() {
        parent::__construct();
        $this->load->database();//used to load db settings and initialize database
    }
    public function entry($data)
    {
        $this->db->select("*");
        $this->db->from('login');
        $this->db->where($data);
        $query=$this->db->get();
        return $query->row();//returns a single row of record as object array
    }
}

login.php

<form method="post" action="<?php echo site_url('emp/login'); ?>">
    <table border="1">
        <tr>
            <td><label>UserId</label></td>
            <td><input type="text" name="userid" ></td>
        </tr>
        <tr>
            <td><label>Password</label></td>
            <td><input type="text" name="password" ></td>
        </tr>
        <tr>
            <td>
                <input type="submit" name="login" value="Login">
            </td>
        </tr>
    </table>

</form>

userdata.php

<?php
echo $this->session->userdata('id');
echo "<br/>";
echo $this->session->userdata('email');


multiple table join in codeigniter

viewpage(employee_data_edit_view)

<form method="post">
    <table border='1'>
        <tr>
            <td><label>Name</label></td>
            <td><input type="text" name="name" value="<?php echo $result->name;?>"></td>
        </tr>
       
         <tr>
            <td><label>Age</label></td>
            <td><input type="text" name="age" value="<?php echo $result->age;?>"></td>
        </tr>
         <tr>
            <td><label>Gender</label></td>
            <td><input type="text" name="gender" value="<?php echo $result->gender;?>"></td>
        </tr>
       
         <tr>
            <td><label>Email</label></td>
            <td><input type="text" name="emailid" value="<?php echo $result->emailid;?>"></td>
        </tr>
       
        <tr>
            <td><label>Panno</label></td>
            <td><input type="text" name="panno" value="<?php echo $result->panno;?>"></td>
        </tr>
       
        <tr>
            <td><label>Phone</label></td>
            <td><input type="text" name="phone" value="<?php echo $result->phone;?>"></td>
        </tr>
       
         <tr>
            <td><label>Address</label></td>
            <td><input type="text" name="address" value="<?php echo $result->address;?>"></td>
        </tr>
       
         <tr>
            <td><label>UserId</label></td>
            <td><input type="text" name="userid" value="<?php echo $result->userid;?>"></td>
        </tr>
         <tr>
            <td><label>Password</label></td>
            <td><input type="text" name="password" ></td>
        </tr>
    </table>
</form>

Controller(employee)
i only providing the function inside the Employee controller class
 public function empdataview($id)
    {
        $this->load->model('employee_model');
    $data=array('empcode'=>$id);
     $query['result']=$this->employee_model->employee_data($data);
    $this->load->view('employee_data_edit_view',$query);
    }
 

Model(employee_model)

public function employee_data($data)
{
     
    $this->db->select(
    'user_info.name,user_info.age,user_info.gender,user_info.panno,user_info.image,user.emailid,user.phone,user.address,userlogin.userid,userlogin.password');
    $this->db->from('user_info');
    $this->db->join('user','user.empcode=user_info.empcode');
    $this->db->join('userlogin','userlogin.empcode=user.empcode');
    $this->db->where('userlogin.empcode',$data['empcode']);
    $query=$this->db->get();
    return $query->row();
}










delete update using jquery in codeigniter

note create a js in codeigniter foler and add jquery to it
create a database database
load url,form_validation,form to auto load.php
set database.php

Form.php(Controller)

<?php
defined('BASEPATH') OR EXIT('Dirrect Access Not Allowed');
class Form_model extends CI_Model
{
    public function __construct() {
        parent::__construct();
        $this->load->database();
    }
    public function add($data)
    {
     return  $this->db->insert('exp_registeration',$data);
     
       
    }
    public function show()
    {
        $query=$this->db->query("SELECT * FROM  exp_registeration");
        return $query->result();
    }
    public function remove($id)
    {
       $this->db->wehre('id',$id);
       $this->db->delete("exp_registeration");
    }
    public function update($data)
    {
        $update_data=array('name'=>$data[0],'age'=>$data[1],'emailid'=>$data[2],'phoneno'=>$data[3],'address'=>$data[4]);
$this->db->where('id',$data[5]);
$this->db->update("exp_registeration",$update_data);
    }
   }?>


form_view.php(view file)

<link href="<?php echo base_url()."/css/style.css"; ?>" rel="stylesheet">
<form method="post" action="<?php echo site_url('Form/insert'); ?>">
    <table border="1" id="table_form">
        <tr>
            <td>
                <label>Name</label>
            </td>
            <td>
                <input type="text" name="student_name" value="<?php echo set_value('student_name');?>">
            </td>
        </tr>
       
        <tr>
            <td>
                <label>Age</label>
            </td>
            <td>
                <input type="text" name="age" value="<?php echo set_value('age');?>">
            </td>
        </tr>
       
        <tr>
            <td>
                <label>Email id</label>
            </td>
            <td>
                <input type="text" name="email_id" value="<?php echo set_value('email_id');?>">
            </td>
        </tr>
       
        <tr>
            <td>
                <label>Phone Number</label>
            </td>
            <td>
                <input type="text" name="phone_number" value="<?php echo set_value('phone_number');?>">
            </td>
        </tr>
       
        <tr>
            <td>
                <label>Address</label>
            </td>
            <td>
                <input type="text" name="address"value="<?php echo set_value('address');?>">
            </td>
        </tr>
       
        <tr>
            <td>
                <label>Password</label>
            </td>
            <td>
                <input type="text" name="password" value="<?php echo set_value('password');?>">
            </td>
        </tr>
       
        <tr>
            <td>
                <label>Retype Password</label>
            </td>
            <td>
                <input type="text" name="rpassword" value="<?php echo set_value('rpassword');?>">
            </td>
        </tr>
       
        <tr>
            <td>
                <input type="submit" name="save" value="Save">
            </td>
            <td>
                <input type="submit" name="show" value="Show">
            </td>
        </tr>
    </table>

</form>
<?php
echo validation_errors();
?>
<?php
if(isset($_REQUEST['show']))
{
    redirect('Form/show');
}
?>


Display_student_data.php(view)

<header>
<!--    <script src="../../js/jquery.js" type="text/javascript"></script>-->
    <script src="<?php echo base_url()."js/jquery.js"?>"></script>
</header>
<form method="post" id="form1">
   
   
    <table border="1">
        <th>Name</th>
        <th>Age</th>
        <th>Email</th>
        <th>Phone NO</th>
        <th>Address</th>
        <th>Operation</th>
<?php
$i=1;
foreach ($result as $data)
{
 
 ?>
        <tr>
            <td><input type="text" name="name" value="<?php echo $data->name;?>" id=<?php echo "name".$i;?>></td>
            <td><input type="text" name="name" value="<?php echo $data->age;?>" id=<?php echo "age".$i;?>></td>
            <td><input type="text" name="name" value="<?php echo $data->emailid;?>" id=<?php echo "email".$i;?>></td>
            <td><input type="text" name="name" value="<?php echo $data->phoneno;?>" id="<?php echo "phone".$i;?>"></td>
            <td><input type="text" name="name" value="<?php echo $data->address;?>" id="<?php echo "address".$i;?>"></td>
            <td><a href="<?php echo site_url()."/Form/edit/".$data->id; ?>" id="edit<?php echo $i;?>">Edit</a>&nbsp;&nbsp;&nbsp;<a href="<?php echo site_url()."/Form/delete/".$data->id;?>" id="delete">Delete</a></td>
        </tr>      
<?php
$i++;
}
?>
    </table>
</form>
<script>
    $(document).ready(function(e)   
    {
      
    limit=<?php echo $i-1;?>;
   
       $('a').click(function(e){
    choice=this.id.substr(0,this.id.length-1);
   
           id_=this.id.slice(-1);
           entryno=this.href.slice(-1);
          
           e.preventDefault();
           if(choice=="edit")
           {
           name=$("#name"+id_).val();
           age=$("#age"+id_).val();
           email=$("#email"+id_).val();
           phone=$("#phone"+id_).val();
           address=$("#address"+id_).val();
           data=name+"/"+age+"/"+email+"/"+phone+"/"+address+"/"+entryno;
           $.ajax({
                    url:'edit',
                    type:'post',
                    processData: false,
                    data:'data='+data,
                    success: function (data, textStatus, jqXHR) {
                        alert('Edited');
                    },
                 
                    });
                }
                else
                {
                   $.ajax({
                       url:'delete',
                       type:'post',
                       processData: false,
                       data:'id='+entryno,
                   });
                }
    });
   
    });
</script>

Form_model.php(model)

<?php
defined('BASEPATH') OR EXIT('Dirrect Access Not Allowed');
class Form_model extends CI_Model
{
    public function __construct() {
        parent::__construct();
        $this->load->database();
    }
    public function add($data)
    {
     return  $this->db->insert('exp_registeration',$data);
     
       
    }
    public function show()
    {
        $query=$this->db->query("SELECT * FROM  exp_registeration");
        return $query->result();
    }
    public function remove($id)
    {
       $this->db->wehre('id',$id);
       $this->db->delete("exp_registeration");
    }
    public function update($data)
    {
        $update_data=array('name'=>$data[0],'age'=>$data[1],'emailid'=>$data[2],'phoneno'=>$data[3],'address'=>$data[4]);
$this->db->where('id',$data[5]);
$this->db->update("exp_registeration",$update_data);
    }
   
   
}


?>

table structure

-- phpMyAdmin SQL Dump
-- version 3.5.1
-- http://www.phpmyadmin.net
--
-- Host: localhost
-- Generation Time: Jul 02, 2015 at 03:50 PM
-- Server version: 5.5.24-log
-- PHP Version: 5.3.13

SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";


/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;

--
-- Database: `database`
--

-- --------------------------------------------------------

--
-- Table structure for table `exp_registeration`
--

CREATE TABLE IF NOT EXISTS `exp_registeration` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(200) NOT NULL,
  `age` int(11) NOT NULL,
  `emailid` varchar(300) NOT NULL,
  `phoneno` int(11) NOT NULL,
  `address` varchar(300) NOT NULL,
  `password` varchar(400) NOT NULL,
  PRIMARY KEY (`emailid`),
  UNIQUE KEY `id` (`id`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=4 ;

--
-- Dumping data for table `exp_registeration`
--

INSERT INTO `exp_registeration` (`id`, `name`, `age`, `emailid`, `phoneno`, `address`, `password`) VALUES
(2, 'hithin', 25, 'hh@gmail.com', 2147483647, 'ekn njarakal', 'c8383b5122dfc6cbf715d84167656d39'),
(3, 'abcf', 25, 'hhiitthhiinn@gmail.com', 2147483647, 'kerela ernakulam njarakal', 'e2fc714c4727ee9395f324cd2e7f331f');

/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;









file upload in codeigniter

fileupload.php (controller)


<?php
defined('BASEPATH') OR EXIT('Dirrect Access Not Allowed');
class Fileupload extends CI_Controller
{
    public function __construct() {
        parent::__construct();
      
    }
    public function index()
    {
        $this->load->view('fileupload_view',array('error'=>''));
      
    }
  
    public function upload()
    {
        $config['allowed_types']='jpg|pdf|png';//setting allowed extensions
        $config['upload_path']='./assets/'; //path
        $this->load->library('upload',$config); //loading library upload and set upload settings
       
        if($this->upload->do_upload('upload'))
        {
           $data=  array('result'=>$this->upload->data());
           $this->load->view('fileupload_result_view',$data);
        }
 else {
            $this->load->view('fileupload_view',array('error'=>$this->upload->display_errors()));
 }
    }
}
?>
fileupload_view.php(view)


<form method="post" enctype="multipart/form-data" action="<?php echo site_url('fileupload/upload');?>">
    <table border="1">
        <tr>
            <td>
                <label>File Name</label>
            </td>
            <td>
                <input type="file" name="upload">
            </td>
        </tr>
        <tr>
            <td>
                <input type="submit" name="save" value="Save">
            </td>
        </tr>
    </table>
</form>
<?php echo $error;?>


fileupload_result_view.php(view)


<?php
foreach ($result as $key=>$data)
{
    echo "<br/>".$key.="".$data;
}
?>



form validation in codeigniter

set libarary form_validation in autoload.php




validation.php


<?php
defined('BASEPATH') OR EXIT('Dirrect script not allowed');
class Validation extends CI_Controller
{
   
function __construct() {
    parent::__construct();
}  
public function index()
{
    $this->load->view('Validation_view');
}
public function validate()
{
    $this->form_validation->set_rules('name','User Name','required',array('required'=>'please enter a user name'));
    $this->form_validation->set_rules('age','Age ','required|numeric');
    $this->form_validation->set_rules('email','Email','required|valid_email');
    $this->form_validation->set_rules('phoneno','Phone number','required|numeric|max_length[10]');
    $this->form_validation->set_rules('password','password','trim|md5|required');
    $this->form_validation->set_rules('rpassword','password','md5|trim|required|matches[password]');
    if($this->form_validation->run()==FALSE)
    {
        $this->load->view("validation_view");
    }
 else {
        echo 'no error';
    }
}
}
?>


validation_view.php


<?php echo validation_errors();?>
<form method="post" action="<?php echo site_url('validation/validate')?>">
    <table border="1">
        <caption><h1>Registeration</h1></caption>
        <tr>
            <td>
                <label>Name</label>
            </td>
            <td>
                <input type="text" name="name" value="<?php echo set_value('name'); ?>">
            </td>
        </tr>
        <tr>
            <td>
                <label>Age</label>
            </td>
            <td>
                <input type="text" name="age" value="<?php echo set_value('age');?>">
            </td>
        </tr>
       
         <tr>
            <td>
                <label>Email</label>
            </td>
            <td>
                <input type="text" name="email" value="<?php echo set_value('email');?>">
            </td>
        </tr>
        <tr>
            <td>
                <label>Phone No</label>
            </td>
            <td>
                <input type="text" name="phoneno" value="<?php echo set_value('phoneno');?>">
            </td>
        </tr>
       
        <tr>
            <td>
                <label>Password</label>
            </td>
            <td>
                <input type="text" name="password" value="<?php echo set_value('password');?>">
            </td>
        </tr>
       
        <tr>
            <td>
                <label>Retype Password</label>
            </td>
            <td>
                <input type="text" name="rpassword" value="<?php echo set_value('rpassword');?>">
            </td>
        </tr>
       
       
        <tr>
            <td>
                <input type="submit" name="save" value="Save">
            </td>
        </tr>
       
    </table>
</form>







simple login example in codeigniter

set
$autoload['libraries'] = array('database'); ,$autoload['helper'] = array('url','form');
set database.php database entries like hostname,user,password,databasename
create a controller entry.php


<?php
defined("BASEPATH") OR exit("Dirret Sript Not Allowed");
class Entry extends CI_Controller
{
  function __construct()
  {
      parent::__construct();
  } 
  public function index()
  {
      $this->load->view("entryview");
  }
  public function login()
  {
      $this->load->model("entrymodel");
      $status=$this->entrymodel->validate();
     
      if($status==1)
      {
          redirect("member");
      }
      else
      {
          echo "invalid user";
      }  
  }
   public function signin()
   {
       $this->load->view("create_new_user");
      
   }
   public function register()
   {
       $this->load->model("create_new_user_model","obj");
       $status=$this->obj->create();
       if($status)
       {
           redirect("entry");
       }
   }
}


?>


create  a model entrymodel.php


<?php
defined("BASEPATH") OR exit("Dirrect Access Not Allowed");
class Entrymodel extends CI_Model
{
   
    function __construct() {
        parent::__construct();
    }
   
    public function validate()
    {
        $this->db->where('email',  $this->input->post('emailid'));
        $this->db->where('password',  $this->input->post('password'));
        $query=$this->db->get('login');
        return $query->num_rows();
    } 
}
?>


create a view page create_new_user.php


<form method="post"  action="<?php echo site_url("entry/login")?>" >
      <table border="1">
          <tr>
              <td>
                  <label>UserId</label>
              </td>
              <td>
                  <input type="text" name="emailid">
                 
              </td>
          </tr>
          <tr>
              <td>
                  <label>
                      Password
                  </label>
              </td>
              <td>
                  <input type="text" name="password">
                 
              </td>
             
          </tr>
          <tr>
              <td>
                  <input type="submit" name="submit" value="Login">
              </td>
              <td>
                  <a href="<?php echo base_url(); ?>index.php/entry/signin">Register</a>
                 
              </td>
          </tr>
    </table>
 
 
 







how to display images and genderate popup image when click using jqueryui,php,mysql

imagedisplay.php
<link rel="stylesheet" type="text/css" href="css/stylesheet.css">
<link href="http://code.jquery.com/ui/1.10.4/themes/ui-lightness/jquery-ui.css" rel="stylesheet">
      <script src="http://code.jquery.com/jquery-1.10.2.js"></script>
      <script src="http://code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
<?php
@mysql_connect("localhost","root","");
@mysql_select_db("database");
$query="select * from gallery";
$temp=@mysql_query($query);
?>
      <div id="imagedisplay" >
    <img src="#" id="dialogimage">
</div>

<div id="image">
    <?php while ($result=@mysql_fetch_assoc($temp))
    {
        //echo $result["imagepath"];
        ?>
    <a href="imagedisplay.php?id=<?php echo $result["id"];?>" id="atag">
    <img src="<?php echo $result["imagepath"];?>">
    </a>
    <?php }?>
</div>
      <script type="text/javascript">
      $(document).ready(function(e){
           $( "#imagedisplay" ).dialog({
               autoOpen: false,
               width:700,
               height:00,
               model:true,
               resizable:false
            });
            $(".ui-button").click(function(e){
               $("#image").show();
            });
          $("a").click(function(e){
              e.preventDefault();
             
              var id="imagedisplayscript.php?id="+this.href.slice(-1);
            
             $.ajax(
                     {
                         url:id,
                 processData: false,
                 cache: false,
                 type: 'POST',
                 success: function (data, textStatus, jqXHR) {
                   
                     $("#dialogimage").attr("src",data);
                       //$("#imagedisplay").css(" background-image", 'url("'+data+'")');
                       $("#dialogimage").css("height","500px");
                       $("#dialogimage").css("width","500px");
                         $( "#imagedisplay" ).dialog( "open" );
                         $("#image").hide();
                    }
                     });
                     });
      });
      </script>

stylesheet.css
#image
{
    width: 500px;
    height: 500;
    border-bottom-style: inset;
    border-bottom-width: 1px;
    border-bottom-color: black;
}
img
{
    height: 200px;
    width: 200px;
    border: black;
    border-bottom-style: double;
}
.ui-widget-header,ui-state-default,ui-button
{
            background:activeborder;
               // #b9cd6d;
            border: 1px solid black;
            color: #FFFFFF;
            font-weight: bold;
          
}
.ui-dialog ,ui-widget,ui-widget-content,ui-corner-all,ui-front ,ui-draggable,ui-resizable
{
    height: 800px;
    width: 800px;
}
.ui-dialog-content,ui-widget-content
{

    height: 520px;
    width: 495px;
}


imagedisplayscript.php
<?php
@mysql_connect("localhost","root","");
@mysql_select_db("database");
$query="select * from gallery where id=".$_REQUEST["id"];
$temp=@mysql_query($query);
$result=@mysql_fetch_assoc($temp);
echo $result["imagepath"];
?>




















how to create a autocomplete text box using php,jquery,mysql

select.php
<?php
@mysql_connect("localhost","root","");
@mysql_select_db("example");
$query="select * from auto";
$tempdata=@mysql_query($query);
$name=array();
while($data=@mysql_fetch_assoc($tempdata))
{
$name[]=$data["name"];
}
echo json_encode($name);
?>

page.php
<head>
    <link href="http://code.jquery.com/ui/1.10.4/themes/ui-lightness/jquery-ui.css" rel="stylesheet">
      <script src="http://code.jquery.com/jquery-1.10.2.js"></script>
      <script src="http://code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
</head>


    <div class="ui-widget">
    <input type="text" id="automplete-1">
    </div>

<script type="text/javascript">
$(document).ready(function()
{
    var name=<?php include 'select.php'; ?>;
    $("#automplete-1").autocomplete({
        source: name,
        autoFocus:true
    });
});
</script>


how to upload and display image before submiting using php and jquery

main.php
<head>
    <link href="css/style.css" type="text/css" rel="stylesheet"/>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
</head>
<form method="post" enctype="multipart/form-data" action="upload.php" id="form1">
    <div id="imagePreview">
       
    </div>
<input id="uploadFile" type="file" name="image" class="img" />
<input type="submit" name="save" id="save">
</form>
<script type="text/javascript">
$(document).ready(function(){
    $("#uploadFile").on("change", function()
    {
        var files = !!this.files ? this.files : [];
         // no file selected, or no FileReader support

        // only image file
            var reader = new FileReader(); // instance of the FileReader
            reader.readAsDataURL(files[0]); // read the local file
          reader.onloadend = function()
            { // set image data as background of div
                $("#imagePreview").css("background-image", "url("+this.result+")");
            }
       
    });
    $("#form1").on("submit",function (e)
    {
        e.preventDefault();
        $.ajax(
                {
                    url:"upload.php",
                    type:"post",
                    cache: false,
                    contentType: false,
                    processData: false,
                    data:new FormData(this),
                    success: function (data, textStatus, jqXHR) {
                        alert(data);
                    }
                });
    }
                );
  
   
});
</script>

upload.php
<?php
if(is_array($_FILES))
{
    $destination="image/".$_FILES["image"]["name"];
    $source=$_FILES["image"]["tmp_name"];
   if( move_uploaded_file($source, $destination))
   {
       echo "image uploaded";
   }
   
}

?>

style.css
#imagePreview
{
width: 180px;
    height: 180px;
    background-position: center center;
    background-size: cover;
    -webkit-box-shadow: 0 0 1px 1px rgba(0, 0, 0, .3);
    display: inline-block;
}

How to create a simple captcha

<?php
session_start();
$code=rand(1000,9999);
$_SESSION["code"]=$code;
$image=imagecreatetruecolor(50,24);
$background_color=imagecolorallocate($image,22,100,165);
$forground_color=imagecolorallocate($image,225,225,225);
imagefill($image,0,0,$background_color);
imagestring($image,5,5,5,$code,$forground_color);
header("Cache-Control:no-cache,must-revalidate");
header('Content-type: image/png');
imagepng($image);
imagedestroy($image);
?>


call this file in <img src="above file.php" />

How to load json data into a page using jquery and ajax

jason.php

<script type="text/javascript" src="../jquery/jquery-1.11.1.min.js"></script>
<script>
$(document).ready(function(e) {
    $.ajax(
    {
        url:"country.json",dataType:"json",success: function(response)
    {
        $("#result").html("First name="+response.first_name);
        $("#result2").html("Last Name="+response.last_name);
    }
    });
});
</script>
<div id="result"></div>
<div id="result2"></div>

country.json

{
"first_name":"Hithin ",
"last_name":"Chandran",
"third":"3.yyy"
}

how to display a textfile data using jquery ajax techniqe

<script type="text/javascript" src="jquery-1.11.1.min.js"></script>
<div id="txt">
</div>
<input type="button" id="Load" value="Load">
<script>
$(document).ready(function(e) {
    $("#Load").click(function(e) {
        $.ajax(
        {
            url:"text.txt",
            success: function(result)
        {
            $("#txt").text(result);
        },error: function(result)
        {
        }
        });
    });
});
</script>