Tuesday 27 December 2016

Load more button data show with ajax in php.

index.php =>

             $rowperpage = 5;
            // counting total number of posts
            $allcount_query = "SELECT count(*) as allcount FROM signup where type='teacher'";
            $allcount_result = mysql_query($allcount_query);
            $allcount_fetch = mysql_fetch_array($allcount_result);
            $allcount = $allcount_fetch['allcount'];

            // select first 5 posts
            $query = "select * from signup where type='teacher' order by id DESC limit 0,$rowperpage ";
            $result = mysql_query($query);

            while($row = mysql_fetch_array($result)){

//your code here...............you want to show .
 
            }
}
            ?>
            <h1 class="load-more button btn">Load More</h1>
            <input type="hidden" id="row" value="0">
            <input type="hidden" id="all" value="<?php echo $allcount; ?>">



.js file =>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>

  <script type="text/javascript">
$(document).ready(function(){

    // Load more data
    $('.load-more').click(function(){
        var row = Number($('#row').val());
        var allcount = Number($('#all').val());
        var rowperpage = 5;
        row = row + rowperpage;

        if(row <= allcount){
            $("#row").val(row);

            $.ajax({
                url: 'loadmore.php',
                type: 'post',
                data: {row:row},
                beforeSend:function(){
                    $(".load-more").text("Loading...");
                },
                success: function(response){

                    // Setting little delay while displaying new content
                    setTimeout(function() {
                        // appending posts after last post with class="post"
                        $(".post:last").after(response).show().fadeIn("slow");

                        var rowno = row + rowperpage;

                        // checking row value is greater than allcount or not
                        if(rowno > allcount){

                            // Change the text and background
                            $('.load-more').text("No More Result");
                            $('.load-more').css("background","darkorchid");
                        }else{
                            $(".load-more").text("Load more");
                        }
                    }, 2000);


                }
            });
        }else{
            $('.load-more').text("Loading...");

            // Setting little delay while removing contents
            setTimeout(function() {

                // When row is greater than allcount then remove all class='post' element after 3 element
                $('.post:nth-child(5)').nextAll('.post').remove();

                // Reset the value of row
                $("#row").val(0);

                // Change the text and background
                $('.load-more').text("Load more");
                $('.load-more').css("background","#15a9ce");
             
            }, 2000);


        }

    });

});

  </script>


loadmore.php =>

<?php

//include database configuration file
$row = $_POST['row'];
$rowperpage = 5;

// selecting posts
$query = 'SELECT * FROM signup WHERE type="teacher" order by id DESC limit '.$row.','.$rowperpage;
$result = mysql_query($query);
while($row = mysql_fetch_array($result)){ 

your code here after load more data show.


} ?>



Tuesday 6 December 2016

Page onload automatic click button and link in jquery.

<script>
window.onload = function(){
  document.getElementById("autopop").click();
}
</script>
</head>
<body>
<a href="#" class="link-login" id="autopop"></a>

Friday 18 November 2016

Ajax Search in php

(index.php)

<div id="content">
<input type="text" class="search" id="searchid" placeholder="Search for parent profile" />
&nbsp; &nbsp; Example : manjeet, manjeet@gmail.com, 998822<br />
<div id="result">
</div>

</div>

(js.php)

<script type="text/javascript" src="jquery-1.8.0.min.js"></script>
<script type="text/javascript">
$(function(){
$(".search").keyup(function()
{
var searchid = $(this).val();
var dataString = 'search='+ searchid;
if(searchid!='')
{
    $.ajax({
    type: "POST",
    url: "search.php",
    data: dataString,
    cache: false,
    success: function(html)
    {
    $("#result").html(html).show();
    }
    });
}return false;  
});

jQuery("#result").live("click",function(e){
    var $clicked = $(e.target);
    var $name = $clicked.find('.name').html();
    var decoded = $("<div/>").html($name).text();
    $('#searchid').val(decoded);
});
jQuery(document).live("click", function(e) {
    var $clicked = $(e.target);
    if (! $clicked.hasClass("search")){
    jQuery("#result").fadeOut();
    }
});
$('#searchid').click(function(){
    jQuery("#result").fadeIn();
});
});

</script>


(search.php)

if($_POST)
{
$q=$_POST['search'];
$sql_res=mysql_query("SELECT * FROM `signup` WHERE `first_name` LIKE '%$q%' OR `email` LIKE '%$q%' OR `mobile` LIKE '%$q%' order by id LIMIT 5");
while($row=mysql_fetch_array($sql_res))
{
$username=$row['first_name'];
$email=$row['email'];
$b_username='<strong>'.$q.'</strong>';
$b_email='<strong>'.$q.'</strong>';
$final_username = str_ireplace($q, $b_username, $username);
$final_email = str_ireplace($q, $b_email, $email);
?>
<?php
if($row['type']=='parent'){?>
<div class="show" align="left">
<div onclick="send(<?php echo $row['id']; ?>)"><img src="<?php echo SITE_URL; ?>img/zs.png" style="width:50px; height:50px; float:left; margin-right:6px;" /><span class="name"><?php echo $final_username; ?></span>&nbsp;<br/><?php echo $final_email; ?>&nbsp;<br/><?php echo $row['mobile']; ?><br/></div>
</div>
<?php }
}
}

Friday 30 September 2016

How to use php varible in javascript.

<?php
$varible = "get any string or fetch any data from database";

   ?>
       <script type="text/javascript">
   var show= "<?php echo strip_tags($varible); ?>";
  alert(show);
  </script>

How to use javascript Function in php

<a href="javascript:readmore(id)"> Read More </a>

<script type="text/javascript">
function readmore(id)
{
 if(confirm('Sure To Remove This Chat ?'))
     {
        window.location.href='?readmore='+id;
      }
}
</script>

Tuesday 13 September 2016

how to share any post on facebook in php

<?php
$data = "pppppppppppppppppppppppppppp";

?>
<html>
     

<head>
    <title>Facebook Share Button - External Website</title>
   
<style type="text/css">

body { 
background:#f5f5f5;
font: 14px/150% 'century gothic',helvetica,arial;
}

#container {
margin:5px auto;
padding:25px;
width:400px;
border:1px solid #999;
border-radius:8px; -moz-border-radius:8px; -webkit-border-radius:8px;
background:#fff;
}
</style>


</head>

<body>

<div id="container">

<p>Manjeet kashyap</p>

<div id="fb-root"></div>


<script>
 window.fbAsyncInit = function() {
FB.init({

 appId  : '964579503687504',
 status : true, // check login status
 cookie : true, // enable cookies to allow the server to access the session
 xfbml  : true  // parse XFBML
});
 };

 (function() {
var e = document.createElement('script');
e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
e.async = true;
document.getElementById('fb-root').appendChild(e);
 }());
</script>


<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js" type="text/javascript"></script>

<img id = "share_button" src = "http://app.tabpress.com/fbui_share/share_button.png">

<script type="text/javascript">
$(document).ready(function(){
$('#share_button').click(function(e){

e.preventDefault();
var m = "<?php echo $data; ?>";
FB.ui(
{

method: 'feed',
name: 'HyperArts Blog',
link: 'http://hyperarts.com/blog',
picture: 'http://www.hyperarts.com/_img/TabPress-LOGO-Home.png',
caption: 'I love HyperArts tutorials',
description: m,
message: ''
});
});
});
</script>


</div>

</body>
</html>

Friday 9 September 2016

how to check email valid on server in php.

$email = "john@gmail.com";

if (!filter_var($email, FILTER_VALIDATE_EMAIL) === false) {
  echo("$email is a valid email address");
} else {
  echo("$email is not a valid email address");
}

Tuesday 6 September 2016

how to call page content in template file in wordpress.

<?php while ( have_posts() ) : the_post(); ?>
<?php get_template_part( 'content', 'page' ); ?>
<?php comments_template( '', true ); ?>
<?php endwhile; // end of the loop. ?>

Sunday 21 August 2016

how to get address from latitude and longitude.

$geocode=file_get_contents('http://maps.googleapis.com/maps/api/geocode/json?latlng=30.6978446,76.717779&sensor=false');

$output= json_decode($geocode);
//print_r($output);
echo $output->results[0]->formatted_address;

how to get latitude and longitude from Address .

$address = 'sector 70 mohali';

$geo = file_get_contents('http://maps.googleapis.com/maps/api/geocode/json?address='.urlencode($address).'&sensor=false');

$geo = json_decode($geo, true);

if ($geo['status'] == 'OK') {
 $latitude = $geo['results'][0]['geometry']['location']['lat'];
 $longitude = $geo['results'][0]['geometry']['location']['lng'];
}

Tuesday 9 August 2016

how to create REST API in php

Simple three Step create Rest API 

STEP->1 create config.php

STEP-> 2create api.php

STEP-> 3create class.api.php


how to create php mysql connection with object

<?php
$host ='localhost';
$username ='username?';
$password ='password?';
$db = 'databasename?';
$con = new mysqli($host, $username, $password, $db);
if(mysqli_error($con))
{
printf("Connect failed %s\n",mysqli_connect_error());
}
?>

Tuesday 2 August 2016

how to send email with html formate in php wordpress

$message = '<html><body>';
$message .= '<img src="http://css-tricks.com/examples/WebsiteChangeRequestForm/images/wcrf-header.png" alt="Website Booking Request" />';
$message .= '<table rules="all" style="border-color: #666;" cellpadding="10">';
$message .= "<tr style='background: #eee;'><td><strong>First Name:</strong> </td><td>" . strip_tags($_POST['firstname']) . "</td></tr>";
$message .= "<tr style='background: #eee;'><td><strong>Last Name:</strong> </td><td>" . strip_tags($_POST['lastname']) . "</td></tr>";
$message .= "<tr><td><strong>Email:</strong> </td><td>" . strip_tags($_POST['email']) . "</td></tr>";
$message .= "<tr><td><strong>Phone No:</strong> </td><td>" . strip_tags($_POST['phone']) . "</td></tr>";
$message .= "<tr><td><strong>Address:</strong> </td><td>" . strip_tags($_POST['address']) . "</td></tr>";
$message .= "<tr><td><strong>city:</strong> </td><td>" . strip_tags($_POST['city']) . "</td></tr>";
$message .= "<tr><td><strong>state:</strong> </td><td>" . $_POST['state'] . "</td></tr>";
$message .= "<tr><td><strong>Zip Code:</strong> </td><td>" . htmlentities($_POST['zipcode']) . "</td></tr>";
$message .= "<tr><td><strong>Comming Date:</strong> </td><td>" . htmlentities($_POST['choose_date']) . "</td></tr>";
$message .= "<tr><td><strong><h3 style='background: #eee;'>Booking Add Successfull</h3></strong> </td><td>";
$message .= "</table>";
$message .= "</body></html>";

//  MAKE SURE THE "FROM" EMAIL ADDRESS DOESN'T HAVE ANY NASTY STUFF IN IT

$pattern = "/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/i";
         if (preg_match($pattern, trim(strip_tags($_POST['email'])))) {
            $cleanedFrom = trim(strip_tags($_POST['email']));
          } else {
             return "The email address you entered was invalid. Please try again!";
           }

            //   CHANGE THE BELOW VARIABLES TO YOUR NEEDS
           
$to = "you emai id ";

$subject = 'subject';

$headers = "From: " . $cleanedFrom . "\r\n";
$headers .= "Reply-To: ". strip_tags($_POST['email']) . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";

            if (wp_mail($to, $subject, $message, $headers)) {
              echo 'email send successfull.';
            } else {
              echo 'There was a problem sending the email.';
            }

NOTE : if You code is use in php only use mail($to, $subject, $message, $headers) function.
  

Monday 1 August 2016

how to integrate paypal in php

    NOTE: Follow some Step:
1. Log in to your PayPal account at https://www.paypal.com. The My Account Overview page appears.
 2.  Click the Profile subtab. The Profile Summary page appears.
 3.  Click the My Selling Tools link in the left column.
 4.  Under the Selling Online section, click the Update link in the row for Website Preferences. The Website Payment Preferences page appears
 5. Under Auto Return for Website Payments, click the On radio button to enable Auto Return.
 6.  In the Return URL field, enter the URL to which you want your payers redirected after they complete their payments. NOTE: PayPal checks the Return URL that you enter. If the URL is not properly formatted or cannot be validated, PayPal will not activate Auto Return.
7.    Scroll to the bottom of the page, and click the Save button.

8. show all post data like confirmation message get (redirect url page ) 


      $ammout = "your account like $10";
     $paypal_url='https://www.paypal.com/cgi-bin/webscr'; // Test Paypal API URL
        $paypal_id='info@gmail.com'; // Business email ID

       $paypal_url='https://www.sandbox.paypal.com/cgi-bin/webscr'; // Test Paypal API URL
       $paypal_id='mminfo@.com'; // Business email ID 


        <form method="post" action='<?php echo $paypal_url; ?>'>
         <input type='hidden' name='business' value='<?php echo $paypal_id; ?>'>    
        <input type='hidden' name='cmd' value='_xclick'>
          <br/>
         <input type='hidden' name='item_name' value='Tour-package'>
           <input type='hidden' name='item_number' value='001'>
         <input type='hidden' name='amount' value='<?php echo $amount; ?>'>
         <input type='hidden' name='rest_amount' value='<?php echo $rest_amount; ?>'>
         <input type='hidden' name='cancel_return' value='<?php echo $site_url;?>/cancel'>
         <input type='hidden' name='custemail' value='<?php echo $email; ?>'>
         <input type="hidden" name="rm" value="2">
         <input type="submit" class="sbt-btn-book" name="member-submit" class="sub-btn" value="Submit">
       </form> 

Sunday 31 July 2016

how to create a dynamic drop-down in wordpress

<?php
global $wpdb;
$select_query= $wpdb->get_results( 'SELECT * FROM wp_add_bed_service');
echo "<select class='form-control' id='badroom-1' name='bedroom'>";
foreach ($select_query as $select_queryy )
{
  echo "<option value='$select_queryy->price' >".htmlspecialchars($select_queryy->bedroom)."</option>";
}
echo "</select>";

?>

Thursday 28 July 2016

how to add datepiker in text field

<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.0/jquery-ui.js"></script>
<script>
$( function() {
$( "#datepicker" ).datepicker();
} );
</script>
</head>
<body>
<p>Date: <input type="text" id="datepicker"></p>
</body>

Thursday 2 June 2016

html form with insert data in php

<html>
<head>
<link rel="stylesheet" href="int.css" />
<style>
.error {color: #FF0000;}
</style>
</head>
<body>
<?php
$i_namea = $f_namea = $emaila = $contacta= $r_filea = "";
$i_name = $f_name = $email = $contact= $r_file =  "";

if ($_SERVER["REQUEST_METHOD"] == "POST") {
   if (empty($_POST["i_name"])) {
     $i_namea = "Intervier name is required";
   } else {
     $i_name = test_input($_POST["i_name"]);
   }
 
   if (empty($_POST["f_name"])) {
     $f_namea = "father name is required";
   } else {
     $f_name = test_input($_POST["f_name"]);
   }
   
   if (empty($_POST["email"])) {
     $emaila = "email id is required";
   } else {
     $email = test_input($_POST["email"]);
   }
    if (empty($_POST["contact"])) {
     $contacta = "contact is required";
   } else {
     $contact = test_input($_POST["contact"]);
   }

   }
function test_input($data) {
   $data = trim($data);
   $data = stripslashes($data);
   $data = htmlspecialchars($data);
   return $data;
}
?>
<div id="mainform">
<!-- Required Div Starts Here -->
<form id="form" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" method="post" enctype="multipart/form-data">
<h3>Intervier Form</h3>
<p id="returnmessage"></p>
<label>Name: <span>*</span></label>
<input type="text" name="i_name" placeholder="Name"/>
 <span class="error"><?php echo $i_namea; ?></span></br>
<label>Father Name: <span>*</span></label>
<input type="text" name="f_name" placeholder="father Name"/>
 <span class="error"><?php echo $f_namea; ?></span></br>
<label>Email: <span>*</span></label>
<input type="text" name="email" placeholder="Email"/>
<span class="error"><?php echo $emaila; ?></span></br>
<label>Contact No: <span>*</span></label>
<input type="text" name="contact" placeholder="10 digit Mobile no."/>
 <span class="error"><?php echo $contacta; ?></span></br>
<label>Resume: <span>*</span></label>
<input type="file" name="r_file">
<input type="hidden" name='id' value="<?php echo $_GET['id']; ?>" >
<input type="submit" name="submit" value="submit"/>
<a href="profile.php"><input type="button" name="" value="back"></a>
</form>
</div>
</body>
</html>
<?php include 'db.php' ?>
<?php
 if(isset($_POST['submit']))
 {
$i_name=$_POST['i_name'];
$f_name =$_POST['f_name'];
$email =$_POST['email'];
$contact =$_POST['contact'];
$info = pathinfo($_FILES['r_file']['name']);
$ext = $info['extension'];
$newname =  uniqid().".".$ext;
$target = 'name/'.$newname;
 move_uploaded_file( $_FILES['r_file']['tmp_name'], $target);
$sql="INSERT INTO inter_detail (i_name ,f_name, email, contact, r_file) VALUES ('$i_name', '$f_name', '$email','$contact','$newname')";
mysql_query($sql) or die(mysql_error());
}
?>

Thursday 19 May 2016

Show post with WP_Query

<?php have_posts();
$my_query = new WP_Query( 'posts_per_page=6' );
                     while ( $my_query->have_posts() ) : $my_query->the_post(); ?>
                     <li>
<a href="<?php echo $post->post_name; ?>">
<h2><?php the_title();?></h2>
<?php the_content( 'Read more ...' ); ?>
</a>
</li>
<?php endwhile; ?>

how to create dynmic menu in one page theme

<ul class="nav navbar-nav">
<?php
global $post;
$args= array('post_type'=>'page', 'orderby'=>'menu_order', 'posts_par_page'=>'-1','order'=>'ASC');
$myposts= get_posts($args);
foreach ($myposts as $post) :setup_postdata($post); ?>
<li class="dropdown"><a href="#<?php echo $post->post_name; ?>"><?php the_title(); ?></a></li>

                             <?php endforeach; ?>


</ul>

Friday 26 February 2016

How to create widget post in sidebar

<?php
/*
Plugin Name: flippercode Widget Pack
Plugin URI: http://flippercode.com
Description: A plugin containing various widgets created in a Flippercode series on WordPress widgets
Version: 0.1
Author: flippercode
Author URI: http://flippercode.com
Text Domain: flippercode
License: GPLv2

*/


class FlipperText_Widget extends WP_Widget {

    public function __construct() {
    
        parent::__construct(
            'flippertext_widget',
            __( 'Flipper Text Widget', 'flippertextdomain' ),
            array(
                'classname'   => 'flippertext_widget',
                'description' => __( 'A basic text widget to demo the flipper series on creating your own widgets.', 'flippertextdomain' )
                )
        );
      
        load_plugin_textdomain( 'flippertextdomain', false, basename( dirname( __FILE__ ) ) . '/languages' );
      
    }

    /** 
     * Front-end display of widget.
     *
     * @see WP_Widget::widget()
     *
     * @param array $args     Widget arguments.
     * @param array $instance Saved values from database.
     */
 public function widget( $args, $instance ) {
        if ( ! isset( $args['widget_id'] ) ) {
            $args['widget_id'] = $this->id;
        }

        $title = ( ! empty( $instance['title'] ) ) ? $instance['title'] : __( 'Recent Posts' );

        /** This filter is documented in wp-includes/widgets/class-wp-widget-pages.php */
        $title = apply_filters( 'widget_title', $title, $instance, $this->id_base );

        $number = ( ! empty( $instance['number'] ) ) ? absint( $instance['number'] ) : 2;
        if ( ! $number )
            $number = 5;
        $show_date = isset( $instance['show_date'] ) ? $instance['show_date'] : false;

        /**
         * Filter the arguments for the Recent Posts widget.
         *
         * @since 3.4.0
         *
         * @see WP_Query::get_posts()
         *
         * @param array $args An array of arguments used to retrieve the recent posts.
         */
        $r = new WP_Query( apply_filters( 'widget_posts_args', array(
            'posts_per_page'      => $number,
            'no_found_rows'       => true,
            'post_status'         => 'publish',
            'ignore_sticky_posts' => true
        ) ) );

        if ($r->have_posts()) :
        ?>
        <?php echo $args['before_widget']; ?>
        <?php if ( $title ) {
            echo $args['before_title'] . $title . $args['after_title'];
        } ?>
        <ul>
        <?php while ( $r->have_posts() ) : $r->the_post(); ?>
            <li>
                <a href="<?php the_permalink(); ?>"><?php get_the_title() ? the_title() : the_ID(); ?></a>
            <?php if ( $show_date ) : ?>
                <span class="post-date"><?php echo get_the_date(); ?></span>
            <?php endif; ?>
            </li>
        <?php endwhile; ?>
        </ul>
        <?php echo $args['after_widget']; ?>
        <?php
        // Reset the global $the_post as this query will have stomped on it
        wp_reset_postdata();

        endif;
    }

 
    /**
      * Sanitize widget form values as they are saved.
      *
      * @see WP_Widget::update()
      *
      * @param array $new_instance Values just sent to be saved.
      * @param array $old_instance Previously saved values from database.
      *
      * @return array Updated safe values to be saved.
      */
    public function update( $new_instance, $old_instance ) {       
        
        $instance = $old_instance;
        $instance['title'] = sanitize_text_field( $new_instance['title'] );
        $instance['number'] = (int) $new_instance['number'];
        $instance['show_date'] = isset( $new_instance['show_date'] ) ? (bool) $new_instance['show_date'] : false;
        return $instance;
        
    }
 
    /**
      * Back-end widget form.
      *
      * @see WP_Widget::form()
      *
      * @param array $instance Previously saved values from database.
      */
    public function form( $instance ) {   
    
        $title     = isset( $instance['title'] ) ? esc_attr( $instance['title'] ) : '';
        $number    = isset( $instance['number'] ) ? absint( $instance['number'] ) : 2;
        $show_date = isset( $instance['show_date'] ) ? (bool) $instance['show_date'] : false;
        ?>
        
        <p><label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' ); ?></label>
        <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo $title; ?>" /></p>

        <p><label for="<?php echo $this->get_field_id( 'number' ); ?>"><?php _e( 'Number of posts to show:' ); ?></label>
        <input class="tiny-text" id="<?php echo $this->get_field_id( 'number' ); ?>" name="<?php echo $this->get_field_name( 'number' ); ?>" type="number" step="1" min="1" value="<?php echo $number; ?>" size="3" /></p>

        <p><input class="checkbox" type="checkbox"<?php checked( $show_date ); ?> id="<?php echo $this->get_field_id( 'show_date' ); ?>" name="<?php echo $this->get_field_name( 'show_date' ); ?>" />
        <label for="<?php echo $this->get_field_id( 'show_date' ); ?>"><?php _e( 'Display post date?' ); ?></label></p>
    
    <?php
    }
    
}

/* Register the widget */
add_action( 'widgets_init', function(){
     register_widget( 'flippertext_widget' );
});

Tuesday 9 February 2016

How to create backend plugin in wordpress

<?php /*
Plugin Name: book management
Description: This plugin will add/edit/delete Funding Method.
Author: Brainz Technologies
Version: 1.0
*/
$siteurl = get_option('siteurl');
define('BOOKMETHD_FOLDER', dirname(plugin_basename(__FILE__)));
define('BOOKMETHD_URL', $siteurl.'/wp-content/plugins/' . BOOKMETHD_FOLDER);
define('BOOKMETHD_FILE_PATH', dirname(__FILE__));
define('BOOKMETHD_DIR_NAME', basename(BOOKMETHD_FILE_PATH));

// this is the table prefix
global $wpdb;
$bookmethd_table_prefix = $wpdb->prefix;
define('BOOKMETHD_TABLE_PREFIX', $bookmethd_table_prefix);

register_activation_hook(__FILE__,'bookmethd_install');
register_deactivation_hook(__FILE__ ,'bookmethd_uninstall');

//table will be created when plugin is activated.
function bookmethd_install()
{
    global $wpdb;
    $table     = BOOKMETHD_TABLE_PREFIX."book_methods";
    $structure = "CREATE TABLE $table (
                 id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,               
                 book_name VARCHAR(150) NOT NULL,
                 author VARCHAR(150) NOT NULL,
                 department VARCHAR(150) NOT NULL,
                price VARCHAR(150) NOT NULL,
                quantity VARCHAR(150) NOT NULL
                 );";
    $wpdb->query($structure);   
}

//table will be deleted when plugin is deactivated.
function bookmethd_uninstall()
{
    global $wpdb;
    $table     =  BOOKMETHD_TABLE_PREFIX."book_methods";
    $structure =  "DROP TABLE if exists $table";
    $wpdb->query($structure);
}

//show menu on left side
add_action('admin_menu','bookmethd_admin_menu');
function bookmethd_admin_menu(){
  add_menu_page('book Method','Manage book', 10, 'manage_book_method', 'wps_manage_book_method','21');
  add_submenu_page('manage_book_method','Add book ','Add new book',10,'addEdit_book_method','wps_addEdit_book_method');
}

function wps_manage_book_method(){
    include 'manage_book.php';
}


function wps_addEdit_book_method(){   
    $action  = $_GET['action'];
    if($action=='edit'){
        include 'addedit_book_method.php';
    }else{
        include 'add_book.php';       
    }
}

?>
<script type="text/javascript">
function deletebookName(id){ 
  if(confirm("Are you sure to delete?")){ 
   jQuery.ajax({
        url: "../wp-content/plugins/reg_form/delete_book_name.php",
        type: 'post',
        dataType: "html",
        data: { f_ID: id },
        success: function( data ) {
            window.location.href = "../wp-admin/admin.php?page=manage_book_method";
        }
    });
  }
}
</script>
<?php
function getdata( $atts )
{
  global $wpdb;
   $table = $wpdb->prefix."book_methods";
  if(!empty($atts['book_names_id']))  {
  echo "<pre>";
  print_r($atts);
 $book_names = $wpdb->get_results("SELECT * FROM $table where id='".($atts['book_names_id'])."'");
 }
 else
 {
 $book_names = $wpdb->get_results("SELECT * FROM $table");
 }
 $htm="";
 $htm.="<table border='0' cellpadding='2' cellspacing='2' width='70%' style='border:5px solid #cdcdcd;'>
 <tr><td><b>ID.No.</b></td>
 <td><b>Book name</b></td>
 <td><b>Author</b></td>
 <td><b>Department</b></td>
 <td><b>price</b></td>
 <td><b>Quantity</b></td>
  </tr>";
  if($book_names){
      $i=1;
     foreach($book_names as $book){
          $book_names_id=  $book->id;       
          $book_name   = $book->book_name;
           $author  = $book->author;
            $department     = $book->department;
             $price  = $book->price;
           $quantity  = $book->quantity;
  $htm.='<tr><td>'.$book_names_id.'</td>
  <td>'.$book_name.'</td>
  <td>'.$author.'</td>
  <td>'.$department.'</td>
  <td>'.$price.'</td>
  <td>'.$quantity.'</td>
  </tr>';
  }
  $htm.='</table>';
print $htm;
  }
  }
add_shortcode('arjun', 'getdata');


?>

Friday 8 January 2016

Show ,Hide Script in php useing button


    <input type="button" value="Hide Box" class="button-hide" />
    <input type="button" value="Show Box" class="button-show"  />
   


 
    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
    <script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js"></script>

    <script>
   
        $(document).ready(function() {
    
            $('.button-show').click(function(){
               
                $("#box").show();
                $("#box1").hide();

            });

            $('.button-hide').click(function(){

                $("#box").hide();
                $("#box1").show();

            });
        });
    </script>
    <script>
    $(document).ready(function() {
           
      $("#box").hide();
      $("#box1").hide();

         
        });

    </script>
 <form action="#" method="get" class="sidebar-form" id="box">
 <div class="input-group">
<p>this is show content </p>
</div>
</form>
               
<form action="#" method="get" class="sidebar-form" id="box1">
<div class="input-group">
<p>this is hide  content </p>
</div>
</form>

Thursday 7 January 2016

how to insert image in database php

 $image=$_FILES['file']['name'];
 <form action=""  enctype="multipart/form-data" >
<input type="file" name="file" id="ExamDeclareResultYes" required/>
 </form

<?php
if(isset($_FILES['file'])){
      $errors= array();
      $file_name = $_FILES['file']['name'];
      $file_size =$_FILES['file']['size'];
      $file_tmp =$_FILES['file']['tmp_name'];
      $file_type=$_FILES['file']['type'];
      $file_ext=strtolower(end(explode('.',$_FILES['file']['name'])));
     
      $expensions= array("jpeg","jpg","png");
     
      if(in_array($file_ext,$expensions)=== false){
         $errors[]="extension not allowed, please choose a JPEG or PNG file.";
      }
     
      if($file_size > 2097152){
         $errors[]='File size must be excately 2 MB';
      }
     
      if(empty($errors)==true){
         move_uploaded_file($file_tmp,"/home/oyp001/public_html/test9/user/images/".$file_name);
         echo "Success";
      }else{
         print_r($errors);
      }
   }
?>