Mysql query to fetch current month data

Sometimes we need to show only current month data in the application ,so for easy handling the data we should use a Mysql query to fetch current month data.Let we check out how to do that using one MySQL query

See below the Mysql query to fetch current month data


SELECT *
FROM leads
WHERE MONTH(date) = MONTH(CURRENT_DATE())
AND YEAR(date) = YEAR(CURRENT_DATE())
// leads= Table Name
// date = date field name


Here we are fetching current month data using the feature MONTH(CURRENT_DATE()) and MONTH(date)

MONTH(CURRENT_DATE()) will result 8 (since current month is Aug)

Next feature we are using in Mysql query to fetch current month data is YEAR(date) and YEAR(CURRENT_DATE())

YEAR(CURRENT_DATE()) will result 2019 (since today is Aug 24 2019)

so actual Mysql query to fetch current month data will work like this

SELECT *
FROM leads
WHERE MONTH(date) = 9
AND YEAR(date) = 2019

so it will fetch all result form database table leads that having date field value is in august month

How to add OTP validation in contact form 7 WordPress plugin

Among the WordPress developers their is always only one option in the case of which form plugin to use, that is contact contact form 7 WordPress plugin. as per the current report their a huge percentage of spam message every website are getting daily from the users, so OTP validation is most suitable solution to block spammers so automatically our question is how to add OTP validation in contact form 7 WordPress plugin

Let see in details

add below code inside admin contact form section see in details below

<div class="pad0 col-12 col-sm-12 col-md-12">[text* telno id:mobileOTP class:inpt_box placeholder "Contact Number"]</div>
<div class="pad0 col-12 col-sm-12 col-md-12">[text* OTP id:mobileOTPField class:inpt_box placeholder "OTP"]</div>
<div class="pad0 col-12 col-sm-12 col-md-12">[text OTPDEMO id:mobileOTPFieldDemo class:inpt_box placeholder "OTP"]</div>

after adding this page we have to work on script

download footer.php from theme folder
add below code top of the page


 <script>
jQuery(document).ready(function(){ 
jQuery("#mobileOTPField").css('display','none'); 
jQuery("#mobileOTPFieldDemo").css('display','none'); 
jQuery("#mobileOTPField_bottom").css('display','none'); 
jQuery("#mobileOTPFieldDemo_bottom").css('display','none'); 
var otp ; 
 jQuery("#mobileOTP").on("blur",function(){
 
 var mobile=jQuery("#mobileOTP").val();
 var name=jQuery("#yourname").val();
 if(mobile!='')
 {
 var otp=Math.floor(Math.random() * (999999 - 100000 + 1)) + 100000;
 jQuery.post("/send_otp.php",
 {
 mobile: mobile,
 name: name,
 otp: otp
 },
 function(data, status){
 console.log("ffffffffff"+data);
 //alert(otp);
 jQuery("#mobileOTPField").css('display','block');
 jQuery("#mobileOTPFieldDemo").val(otp);
 
 } );
 }
});
jQuery("#mobileOTPField").on("click",function(){
jQuery("#mobileOTPField").css('border','0px solid red');
});
jQuery("#mobileOTPField").on("blur",function(){
jQuery("#mobileOTPField").css('border','0px solid red');
 var value_otp=jQuery("#mobileOTPFieldDemo").val();
 var otp=jQuery("#mobileOTPField").val();
 if(value_otp!=otp)
 {
 jQuery("#mobileOTPField").css('border','1px solid red');
jQuery("#mobileOTPField").val(''); 
 }

});
</script>

Finally upload below files(send_otp.php) in root folder

This is main functionality for OTP validation in contact form 7 WordPress plugin

<?php
$mobile_no=$_REQUEST['mobile'];
$name=$_REQUEST['name'];
if($name=='')
{
$name='User'; 
}
$otp=$_REQUEST['otp'];
//$otp=rand(100000, 999999);
$curl = curl_init();
$post_data='<MESSAGE>
 <AUTHKEY>278449AfqSEysssss6tW5cebts7e3c</AUTHKEY>
 <SENDER>TEST API</SENDER>
 <ROUTE>4</ROUTE>
 <CAMPAIGN>TEST API</CAMPAIGN>
 <COUNTRY>TEST Enquiry</COUNTRY>
 <SMS TEXT="Dear '.$name.', %0aPlease use this OTP '.$otp.' to complete your enquiry. %0a%0a-Team TESTOTP" >
 <ADDRESS TO="'.$mobile_no.'"></ADDRESS>
 </SMS>
</MESSAGE>';

curl_setopt_array($curl, array(
 CURLOPT_URL => "https://control.msg91.com/api/postsms.php",
 CURLOPT_RETURNTRANSFER => true,
 CURLOPT_ENCODING => "",
 CURLOPT_MAXREDIRS => 10,
 CURLOPT_TIMEOUT => 30,
 CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
 CURLOPT_CUSTOMREQUEST => "POST",
 CURLOPT_POSTFIELDS => $post_data,
 CURLOPT_SSL_VERIFYHOST => 0,
 CURLOPT_SSL_VERIFYPEER => 0,
 CURLOPT_HTTPHEADER => array(
 "content-type: application/xml"
 ),
));

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

return $otp;
?>

python get environment variable example code

Here our topic is, python get environment variable, in simple how to get value of environment variable in python .so we should cover how to set environment variable and using python get environment variable value
To work with environment variables in Python is the same like working with dictionaries. first you need to import the os module.

import os

/* To get the value of all environment variable value in python*/

 

print(os.environ)

 

/* To set the environment variable value by name in python */

# To Set environment variables in python

os.environ['EMAIL'] = '[email protected]' 

os.environ['USER_ID'] = '4568'




/* To get the environment variable value by name in python */

 

# To get environment variables in python

import os
USER_EMAIL = os.environ.get('EMAIL') 
print(USER_EMAIL)
USER_ID = os.environ.get('USER_ID') 
print(USER_ID)