Sunday, March 31, 2019

How to get the value of selected radio button in a group using jQuery

    $(document).ready(function(){
        $("input[type='button']").click(function(){
            var radioValue = $("input[name='gender']:checked").val();
            if(radioValue){
                alert("Your are a - " + radioValue);
            }
        });
       
    });

Allow Number to insert into text box

function isNumber(evt) {
    evt = (evt) ? evt : window.event;
    var charCode = (evt.which) ? evt.which : evt.keyCode;
    if (charCode > 31 && (charCode < 48 || charCode > 57)) {
        return false;
    }
    return true;
}

onkeypress="return isNumber(event)"

Friday, March 29, 2019

How to: enable CORS in express.js (node.js)

Express.js is one of the most popular node.js frameworks for serving website or build APIs.

Steps to use CROS in node.js

1. npm install cors
2. Use the following code
   var express = require('express')
   var cors = require('cors')
   var app = express()

app.use(cors())

app.get('/userList', function (req, res, next) {
  res.json({msg: 'Enabled the CROS'})
})

app.listen(80, function () {
  console.log('Enabled CORS listening on port 80')
}) 

Friday, March 22, 2019

Saturday, March 16, 2019

How to Import and Export Databases


EXPORT
To Export a database, open up terminal, making sure that you are not logged into MySQL and type :

mysqldump -u [username] -p [database name] > [database name].sql

Import

source filepath.../filename.sql;


Thursday, February 28, 2019

Check Mobile Version in PHP


function isMobile() {
        return preg_match("/(android|avantgo|blackberry|bolt|boost|cricket|docomo|fone|hiptop|mini|mobi|palm|phone|pie|tablet|up\.browser|up\.link|webos|wos)/i", $_SERVER["HTTP_USER_AGENT"]);
    }

Tuesday, February 19, 2019

AES Encryption And Deception

   function dec_enc($action, $string) {
            $output = false;
       
            $encrypt_method = "AES-256-CBC";
            $secret_key = 'This is my secret key';
            $secret_iv = 'This is my secret iv';
       
            // hash
            $key = hash('sha256', $secret_key);
           
            // iv - encrypt method AES-256-CBC expects 16 bytes - else you will get a warning
            $iv = substr(hash('sha256', $secret_iv), 0, 16);
       
            if( $action == 'encrypt' ) {
                $output = openssl_encrypt($string, $encrypt_method, $key, 0, $iv);
                $output = base64_encode($output);
            }
            else if( $action == 'decrypt' ){
                $output = openssl_decrypt(base64_decode($string), $encrypt_method, $key, 0, $iv);
            }
       
            return $output;
        }

Thursday, November 17, 2016

Copy Selected fields from table2 to table1


If we want to set employeeCode in employeeMaster1 from employeeMaster2 for corresponding employeeId 

A join:

UPDATE employeeMaster1 AS t1
  INNER JOIN employeeMaster2 AS t2 ON t1.employeeId = t2.employeeId

SET t1.employeeCode = t2.employeeCode

By Using left join:

UPDATE employeeMaster1 AS t1
  LEFT JOIN employeeMaster2 AS t2 ON t1.employeeId = t2.employeeId
SET t1.employeeCode = t2.employeeCode


A subquery:

UPDATE employeeMaster1
SET employeeCode = (
  SELECT employeeCode
  FROM employeeMaster2
  WHERE employeeId = employeeMaster1.employeeId

)

Saturday, April 23, 2016

Upload Image Using JQuery. Insert Into Database.


How To insert image into Database.
Please follow the below Steps:-

(1) Create a database

   CREATE TABLE IF NOT EXISTS `userinfo` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(222) NOT NULL,
`picture` varchar(222) NOT NULL,
`createdDateTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;

(2) create a folder structure inside your web application folder.

     upload

(3) Create a file with the name index.php

a. Create HTML form
name,userImage
b. load jquery "https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"

c. use id "uploadTopic" for form.

d. Create DIV as follows


e. Place following code at the bottom


4. Create a file upload.php and place the following code:-

mysql_connect("localhost","root","root");
mysql_select_db("test");

if(!empty($_POST))
{
  $name = $_POST['name'];
  if(isset($_FILES['userImage']['name']) && $_FILES['userImage']['name']!='')
  {
 $desired_path = 'upload/';

 $rand=rand(0,999);
 $desired_file_name = $rand.'_'.str_replace(' ','_',strtolower($_FILES['userImage']['name']));

 move_uploaded_file($_FILES['userImage']['tmp_name'], $desired_path . $desired_file_name);
  }

$query_insert="INSERT INTO userInfo SET name = '".$name."',picture='".$desired_file_name."'";
mysql_query($query_insert);
}
?>

Thursday, March 1, 2012

10 Second Highest Salary of Employee


SELECT * FROM employee E1
WHERE 1 = ( SELECT COUNT( DISTINCT salary )
 FROM employee E2
 WHERE E1.salary < E2.salary
  )
   LIMIT 0,10