How to get backup of database

Standard
To save backup of database :
step 1 : Go to “tmp” directory first :
cd /tmp
step 2 : write following command and press enter :
mysqldump -uroot -pXXXX database_name > backup_name.sql

To Recover Saved backup :

step 1 : Go to “tmp” directory first :
cd /tmp
step 2 : write following command and press enter :
mysql -uroot -pXXXX database_name < backup_name.sql

Remove duplicate rows

Standard
To remove duplicate rows from table follow 3 steps :
Step 1 : check duplicacy : it may return some rows if duplicate rows exist
SELECT count(*) as Count,column1,column2 FROM ABC u group by column1,column2 having Count > 1;
Step 2 : remove duplivate rows :
delete n1 from ABC n1 , ABC n2 where n1.id < n2.id and n1. column1= n2.column1 and n1.column2 = n2.column2; //here id,email,zip are column name and ABC is Table name.
Step 3 : check duplicacy : it should return 0 i.e No duplicate row exist
SELECT count(*) as Count,column1,column2 FROM ABC u group by column1,column2 having Count > 1;

How to upload data from excel file to database

Standard
step – 1 : Save excel file in .csv extension .
step – 2 : use below PHP code accordingly your file format.$username = “XXXX”;
$password = “XXXX”;
$hostname = “localhost”;
$dbName=”XXXX”;
//$dbName=”olm”;
if($conn=mysql_connect($hostname,$username,$password))
{}
else{}
mysql_select_db($dbName, $conn);
$filename = “XXX.csv”;
$handle = fopen($filename, “r”);
$udelimiter = ‘,’;
$chk_i = 0;
while (($line = fgetcsv($handle, 6000, $udelimiter)) !== FALSE)
{
$inst_name = $line[0];
$inst_country = ‘USA’;
$inst_state = $line[3];
$inst_city = $line[2];
$inst_zip = $line[4];
$inst_address = $line[1];
$inst_website = $line[5];
$inst_description = $line[6];
if($chk_i != 0)
{
echo $inst_description.'<br/>’;
$q = “insert into installers_list(name,country,state,city,zip,address_line,website,description) values(‘$inst_name’,’$inst_country’,’$inst_state’,’$inst_city’,’$inst_zip’,’$inst_address’,’$inst_website’,’$inst_description’)”;
mysql_query($q);
}
$chk_i++;
}

How to embed PayPal into your site

Standard
following steps have to follow :

step 1 : create an PayPal account on “https://manager.paypal.com/&#8221;.
after creating account on paypal,follow steps to make some account setting.
    1) Go to service settings->SetUp.
    2) To check it in TEST mode set transaction mode – TEST.
    3) PayPal Sandbox email address : (your sandbox email you got at step-2).
    4) Go to service settings->Customize.
    5) Choose layout C.
step 2 : To test your paypal account create your debit card number by creating account on “https://www.sandbox.paypal.com/&#8221;.
step 3 : Create a database table for paypal payments by using following sql query command :

CREATE TABLE `payments` ( `order_id` varchar(50) DEFAULT NULL, `payer_id` varchar(50) DEFAULT NULL, `token` varchar(50) DEFAULT NULL, `secure_token` varchar(50) DEFAULT NULL, `secure_token_id` varchar(50) DEFAULT NULL, `pnref` varchar(50) DEFAULT NULL, `ppref` varchar(50) DEFAULT NULL, `transaction_id` varchar(50) DEFAULT NULL, `bill_to_name` varchar(50) DEFAULT NULL, `bill_to_firstname` varchar(50) DEFAULT NULL, `bill_to_lastname` varchar(50) DEFAULT NULL, `bill_to_country` varchar(50) DEFAULT NULL, `bill_to_email` varchar(50) DEFAULT NULL, `address_to_ship` varchar(50) DEFAULT NULL, `ship_to_city` varchar(50) DEFAULT NULL, `state_to_ship` varchar(50) DEFAULT NULL, `ship_to_zip` varchar(50) DEFAULT NULL, `ship_to_country` varchar(50) DEFAULT NULL, `amt` varchar(50) DEFAULT NULL, `feeamt` varchar(50) DEFAULT NULL, `result` varchar(50) DEFAULT NULL, `resp_msg` varchar(50) DEFAULT NULL, `type` varchar(50) DEFAULT NULL, `tendor` varchar(50) DEFAULT NULL, `method` varchar(50) DEFAULT NULL, `payment_type` varchar(50) DEFAULT NULL, `tax` varchar(50) DEFAULT NULL, `acct` varchar(50) DEFAULT NULL, `proccvv2` varchar(50) DEFAULT NULL, `cvv2match` varchar(50) DEFAULT NULL, `auth_code` varchar(50) DEFAULT NULL, `iavs` varchar(50) DEFAULT NULL, `card_type` varchar(50) DEFAULT NULL, `procavs` varchar(50) DEFAULT NULL, `card_exp_date` varchar(50) DEFAULT NULL, `trans_time` varchar(50) DEFAULT NULL, `correlation_id` varchar(50) DEFAULT NULL, `pending_reason` varchar(50) DEFAULT NULL, `avsdata` varchar(50) DEFAULT NULL, `avsaddr` varchar(50) DEFAULT NULL, `created_date` datetime DEFAULT NULL, `updated_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP ) ENGINE=InnoDB DEFAULT CHARSET=latin1 )

step 4 : Use the following code for intraction with your PayPal :
function gen_token($x)
{
$_rand_src = array(
array(48,57) //digits
, array(97,122) //lowercase chars
, array(65,90) //uppercase chars
);
srand ((double) microtime() * 1000000);
$random_password = “”;
for($i=0;$i<$x;$i++){
$i1=rand(0,sizeof($_rand_src)-1);
$random_password .= chr(rand($_rand_src[$i1][0],$_rand_src[$i1][1]));
}
return $random_password;
}

$secure_token_id = gen_token(36);
$f_cost = $-XXX; //Set your Product cost.
$amt = $f_cost;
$user = “XXXX”; //PayPal username
$vendor = “XXX”; //PayPal vendor
$partner = “PayPal”;
$pswd = “XXXXXX”; //PayPal password
$mode = “LIVE”;
$host_add = “https://pilot-payflowpro.paypal.com&#8221;; //In LIVE mode url should be “https://payflowpro.paypal.com&#8221;

$post_data = “USER=”.$user.
“&VENDOR=”.$vendor.
“&PARTNER=”.$partner.
“&PWD=”.$pswd.
“&CREATESECURETOKEN=Y”.
“&SECURETOKENID=”.$secure_token_id.
“&TRXTYPE=S”.
“&AMT=”.$amt;
//echo $post_data;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $host_add);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);

$resp = curl_exec($ch);
if(!$resp)
{
echo “<p>To order, please contact us.</p>”;
}
parse_str($resp, $arr);
if($arr[‘result’] != 0)
{
echo “<p>To order, please contact us.</p>”;
}
if($resp && $arr[‘result’] == 0)
{
//print_r($arr);
echo ”;
}
step 5 : To switch to LIVE mode folow steps :
    1)Replace transaction mode->LIVE by following above step-1->2 step.
    2)Remove sandbox email entered at above step-1->3 step.
    3)Replace value of php variable “$host_add” used at step-4 to “https://payflowpro.paypal.com&#8221;.

How to call a function inside or outside from iframe source file(javascript)

Standard

Call function of parent file from inside iframe source file :parent.calling_function_name();

Call function of iframe source file from outside parent file :

document.getElementById(“iframe_id”).contentWindow.calling_function_name();

Set style of html-tag by class of iframe source file from outside parent file :

document.getElementById(“iframe_id”).contentWindow.document.getElementsByClassName(‘classname’)[0].style.display = “none”;

Get content of outside parent file :

$(“#htmml_id” , parent.document).html();

Get content of iframe file from parent file:

$(‘#iframe_id’).contents().find(‘#html_tag_id’).html();