Crazy Codding
Crazy Codding is a question and answer blog for programmers.
Wednesday, 17 May 2017
Sunday, 21 December 2014
Replace all php extension with html using .htacess PHP
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^(.*)\.htm$ $1.php [nc]
RewriteEngine on
RewriteRule ^(.*)\.htm$ $1.php [nc]
Labels:
.htacess,
all,
extension,
FollowSymlinks,
html,
php,
Replace,
RewriteEngine,
using
Tuesday, 9 December 2014
Increase Media file upload size in Wordpress Multisite
In WordPress, Maximum upload file size will not change even when changed in the php.ini file.
Here are the steps to change the Maximum upload file size within WP admin:
1. At the top, hover over My Sites and then click Network Admin
2. At the left, hover over Settings and then click Network Settings.
3. Scroll to the bottom of the page and change the Max upload file size to whatever you would like in KB.
4. Click Save Changes.
To get Free assistance and any Query related to Wordpress, html ,css and responsive websites ....
Wednesday, 3 December 2014
PDO (PHP Data Object)
PDO(PHP Data Object) : PDO is a PHP extension for accessing databases in PHP.
Advantages:
1) Security : In MYSQL connection we manually sanitise using mysql_real_escape_string() functions in order to avoid SQL injections. But with PDO this is all taken care for us and means we no longer have to worry about SQL injection.
2) Performance : PDO uses PHP 5′s OOP characteristics (Object Oriented Programming) so it is working with classes and objects. PDO is written in C and compiled into PHP providing a performance increase over solutions written in PHP.
3) PDO provides single interface across multiple databases. That means to easily migrate to a different database engine (SQLite, Oracle, MSSQL, ODBC, etc.)
4) We can use error handling in PDO by using try, catch and throw.
Connection Syntex:
$user = USER_NAME;
$pass = PASSWORD;
$dbh = new PDO('mysql:host=localhost;dbname=test', $user, $pass);
Exception handling in PDO:
try {
$dbh = new PDO('mysql:host=localhost;dbname=test', $user, $pass);
}
catch (PDOException $e) {
print "Error!: " . $e->getMessage() . "<br/>";
die();
}
Prepare query:
Insert query:
$sth = $dbh->prepare("INSERT INTO `table` (`id`, `title`) VALUES (:id, :title)");
$sth->execute(array(':id' => 123,':title' => 'I am the title'));
Select Query:
$sth = $dbh->prepare("SELECT `id`, `title` FROM `table` WHERE `id` > :country_id");
$sth->execute(array(
':country_id' => 200
));
$count = $sth->rowCount();
Advantages:
1) Security : In MYSQL connection we manually sanitise using mysql_real_escape_string() functions in order to avoid SQL injections. But with PDO this is all taken care for us and means we no longer have to worry about SQL injection.
2) Performance : PDO uses PHP 5′s OOP characteristics (Object Oriented Programming) so it is working with classes and objects. PDO is written in C and compiled into PHP providing a performance increase over solutions written in PHP.
3) PDO provides single interface across multiple databases. That means to easily migrate to a different database engine (SQLite, Oracle, MSSQL, ODBC, etc.)
4) We can use error handling in PDO by using try, catch and throw.
Connection Syntex:
$user = USER_NAME;
$pass = PASSWORD;
$dbh = new PDO('mysql:host=localhost;dbname=test', $user, $pass);
Exception handling in PDO:
try {
$dbh = new PDO('mysql:host=localhost;dbname=test', $user, $pass);
}
catch (PDOException $e) {
print "Error!: " . $e->getMessage() . "<br/>";
die();
}
Prepare query:
Insert query:
$sth = $dbh->prepare("INSERT INTO `table` (`id`, `title`) VALUES (:id, :title)");
$sth->execute(array(':id' => 123,':title' => 'I am the title'));
Select Query:
$sth = $dbh->prepare("SELECT `id`, `title` FROM `table` WHERE `id` > :country_id");
$sth->execute(array(
':country_id' => 200
));
$count = $sth->rowCount();
Labels:
catch,
Connection,
insert,
MYSQL,
PDO,
PDO(PHP Data Object),
PDOException,
prepare,
query,
rowCount(),
select,
try
Thursday, 17 July 2014
CSS Media Queries For Common Devices
/* All Smartphones in portrait and landscape ----------- */
@media only screen
and (min-device-width : 320px)
and (max-device-width : 480px) {
/* YOUR STYLE GOES HERE */
}
/* All Smartphones in landscape ----------- */
@media only screen
and (min-width : 321px) {
/* YOUR STYLE GOES HERE */
}
/* All Smartphones in portrait ----------- */
@media only screen
and (max-width : 479px) {
/* YOUR STYLE GOES HERE */
}
/***** ANDROID DEVICES *****/
/* Android 240 X 320 ----------- */
@media only screen
and (max-width: 241px){
/* YOUR STYLE GOES HERE */
}
/* Android(Samsung Galaxy) in portrait 380 X 685 ----------- */
@media only screen
and (min-width: 375px)
and (max-width: 385px){
/* YOUR STYLE GOES HERE */
}
/* Android(Samsung Galaxy) in Landscape 685 X 380 ----------- */
@media only screen
and (min-width: 680px)
and (max-width: 690px){
/* YOUR STYLE GOES HERE */
}
/* Kindle Portrait 600 X 1024 ----------- */
@media only screen
and (min-width: 595px)
and (max-width: 610px){
/* YOUR STYLE GOES HERE */
}
/* Kindle Landscape 1024 X 600 ----------- */
@media only screen
and (min-width: 1000px)
and (max-width: 1030px){
/* YOUR STYLE GOES HERE */
}
/***** ALL GENERATION IPADS *****/
/* iPads in portrait and landscape----------- */
@media only screen
and (min-device-width : 768px)
and (max-device-width : 1024px) {
/* YOUR STYLE GOES HERE */
}
/* iPad in landscape----------- */
@media only screen
and (min-device-width : 768px)
and (max-device-width : 1024px)
and (orientation : landscape) {
/* YOUR STYLE GOES HERE */
}
/* iPad in portrait----------- */
@media only screen
and (min-device-width : 768px)
and (max-device-width : 1024px)
and (orientation : portrait){
/* YOUR STYLE GOES HERE */
}
/***** Retina IPAD 3 & 4*****/
/* Retina iPad 3 & 4 in portrait and landscape----------- */
@media only screen
and (min-device-width : 768px)
and (max-device-width : 1024px)
and (-webkit-min-device-pixel-ratio: 2){
/* YOUR STYLE GOES HERE */
}
/* Retina iPad 3 & 4 in landscape----------- */
@media only screen
and (min-device-width : 768px)
and (max-device-width : 1024px)
and (orientation : landscape)
and (-webkit-min-device-pixel-ratio: 2){
/* YOUR STYLE GOES HERE */
}
/* Retina iPad 3 & 4 in landscape----------- */
@media only screen
and (min-device-width : 768px)
and (max-device-width : 1024px)
and (orientation : portrait)
and (-webkit-min-device-pixel-ratio: 2){
/* YOUR STYLE GOES HERE */
}
/***** IPAD 1 & 2 (ALSO IPAD MINI)*****/
/* iPad 1 & 2 in portrait and landscape ----------- */
@media only screen
and (min-device-width : 768px)
and (max-device-width : 1024px)
and (-webkit-min-device-pixel-ratio: 1){
/* YOUR STYLE GOES HERE */
}
/* iPad 1 & 2 in landscape ----------- */
@media only screen
and (min-device-width : 768px)
and (max-device-width : 1024px)
and (orientation : landscape)
and (-webkit-min-device-pixel-ratio: 1) {
/* YOUR STYLE GOES HERE */
}
/* iPad 1 & 2 in portrait ----------- */
@media only screen
and (min-device-width : 768px)
and (max-device-width : 1024px)
and (orientation : portrait)
and (-webkit-min-device-pixel-ratio: 1){
/* YOUR STYLE GOES HERE */
}
/* Desktops and laptops ----------- */
@media only screen
and (min-width : 1224px) {
/* YOUR STYLE GOES HERE */
}
/* Large screens ----------- */
@media only screen
and (min-width : 1824px) {
/* YOUR STYLE GOES HERE */
}
/* Only iPhone 4 ----------- */
@media
only screen and (-webkit-min-device-pixel-ratio : 1.5),
only screen and (min-device-pixel-ratio : 1.5) {
/* YOUR STYLE GOES HERE */
}
Monday, 14 July 2014
Create your own Autocomplete for Adding Multiple emails using JQuery
<html>
<head>
<style>
#auto_email_to
{
border:1px solid #cccccc;
width:auto;
font-family:verdana, arial, helvetica, sans-serif;
font-size:15px;
height:auto;
margin-top:0px;
list-style:none;
position: absolute; /*display:none;*/
padding: 0;
background-color: #EAEAEA;
z-index:1;
box-shadow:6px 6px 8px #cccccc;
}
#auto_email_to li
{
height:25px;
}
#email_to
{
width:800px;
}
.services li.selected{
background-color:#636060;
color:#ffffff;
}
</style>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js" type="text/javascript">
</script>
<script>
var email_to = ["Albert@tom_jerry123.com","Allen@tom_jerry123.com","Aladin@tom_jerry123.com","Nilesh@tom_jerry123.com","Dharmesh@tom_jerry123.com","Aakesh@tom_jerry123.com","Pankaj@tom_jerry123.com","Vijay@fakebook.com","Manoj@fakebook.com","Zahir@fakebook.com","Mukesh@fakebook.com","Kishor@fakebook.com","Sachin@fakebook.com","Rakesh@fakebook.com"];
$(document).ready(function(){
var seperator = "";
//alert(123);
if($("#email_to").length > 0)
{
$("#email_to").unbind('keyup').keyup(function(e){
var str = $("#email_to").val();
var last_char = str.slice(-1);
if(last_char == ",")
{
seperator = ",";
}
else if(last_char == ";")
{
seperator = ";";
}
if(seperator == ",")
{
if(str.lastIndexOf(",") == -1)
{
//var Index = "";
}
else
{
var Index = str.lastIndexOf(",")+1;
}
}
else if(seperator = ";")
{
if(str.lastIndexOf(";") == -1)
{
//var Index = "";
}
else
{
var Index = str.lastIndexOf(";")+1;
}
}
if(Index < str.length)
{
var result = str.substring(str.lastIndexOf(""+seperator+"") + 1);
if(e.keyCode == 13)
{//("Enter");
var text_value = $("#email_to").val();
var sub_val = text_value.substring(0,text_value.lastIndexOf(""+seperator+""));
var my_value = $(".selected").attr('id');
var final_value = sub_val + seperator + " " + my_value;
if(my_value != undefined)
{
$( "#email_to" ).val(final_value);
$( "#email_to" ).focus();
$("#auto_email_to").slideUp();
$(".services").empty();
}
}
else if(e.keyCode == 38)
{ //up
var selected = $(".selected");
$(".services li").removeClass("selected");
//alert(selected.prev().length);
// if there is no element before the selected one, we select the last one
if (selected.prev().length == 0)
{
var child = selected.siblings().length + 1;
//alert(child);
$(".services li:nth-child("+child+")").addClass("selected");
}
else
{ // otherwise we just select the next one
selected.prev().addClass("selected");
}
}
else if(e.keyCode == 40)
{ //down
var selected = $(".selected");
$(".services li").removeClass("selected");
if (selected.next().length == 0)
{
$(".services li:nth-child(1)" ).addClass("selected");
}
else
{
selected.next().addClass("selected");
}
}
else
{
call_email(result, "email_to", seperator);
}
}
else
{
if(e.keyCode == 13)
{ // enter
if ($(".services").is(":visible"))
{
my_value = $(".selected").attr('id');
$( "#email_to" ).val(my_value);
$(".product_class").empty();
$(".services").empty();
$("#auto_email_to").slideUp();
}
else
{
$(".services").show();
}
//menuOpen = !menuOpen;
}
else if(e.keyCode == 38)
{ // up
var selected = $(".selected");
$(".services li").removeClass("selected");
// if there is no element before the selected one, we select the last one
if (selected.prev().length == 0)
{
var child = selected.siblings().length + 1;
$(".services li:nth-child("+child+")").addClass("selected");
}
else
{ // otherwise we just select the next one
selected.prev().addClass("selected");
}
}
else if(e.keyCode == 40)
{ // down
var selected = $(".selected");
$(".services li").removeClass("selected");
if (selected.next().length == 0)
{
$(".services li:nth-child(1)" ).addClass("selected");
}
else
{
selected.next().addClass("selected");
}
}
else
{
call_name("email_to");
}
}
});
}
});
function call_email(value, param, seperator)
{
//alert(seperator);
$(".services").empty();
var biller_name = value.toUpperCase().trim();
//alert(biller_name + " " + param);
var container = "";
$("#auto_"+param+"").empty();
if(biller_name != "")
{
if(param == "email_to")
{
var j = 0;
for(i=0;i<email_to.length;i++)
{
container = email_to[i].toUpperCase().toString();
if(container.indexOf(biller_name) >= 0)http://jsfiddle.net/7418/hzZJA/1/
{
if(j == 0){var selected = 'selected';}else{var selected = 'abc';}
$("#auto_"+param+"").append("<li class='listing "+selected+"' id='"+email_to[i]+"'>"+email_to[i]+"</li>");
j++;
}
else
{
$(".services").hide();
}
}
}
$("#auto_"+param+"").slideDown();
$(".services li").mouseover(function() {
//alert(param);
http://jsfiddle.net/7418/hzZJA/1/ $(".services li").removeClass("selected");
$(this).addClass("selected");
});
$(".services li").click(function() {
var text_value = $("#"+param+"").val();
var sub_val = text_value.substring(0,text_value.lastIndexOf(""+seperator+""));
//alert(sub_val);
var my_value = $(this).attr('id');
var final_value = sub_val + seperator + " " + my_value;
selectOption(final_value, param);
$("#"+param+"").focus();
$(".services").empty();
$("#auto_"+param+"").slideUp();
});
}
else
{
$("#auto_"+param+"").slideUp();
}
}
function call_name(param)
{
$(".services").empty();
//alert(param);
var temp_name = $("#"+param+"").val().toUpperCase().trim();
var container = "";
$("#auto_"+param+"").empty();
if(temp_name != "")
{
if(param == "email_to")
{
var j = 0;
for(i=0;i<email_to.length;i++)
{
container = email_to[i].toUpperCase().toString();
if(container.indexOf(temp_name) >= 0)
{
if(j == 0){var selected = 'selected';}else{var selected = 'abc';}
$("#auto_"+param+"").append("<li class='listing "+selected+"' id='"+email_to[i]+"'>"+email_to[i]+"</li>");
j++;
}
else
{
$("#auto_"+param+"").hide();
}
}
}
$(".services li").mouseover(function()
{
$(".services li").removeClass("selected");
$(this).addClass("selected");
});
$(".services li").click(function() {
var my_value = $(this).attr('id');
selectOption(my_value, param);
$(".product_class").empty();
$(".services").empty();
});
var my_width = $("#"+param+"").width() + 5;
$("#auto_"+param+"").width(my_width);
$("#auto_"+param+"").width(my_width);
$("#auto_"+param+"").slideDown();
if(param != "email_to")
{
$("#"+param+"").unbind('blur').blur(function() {
var my_value = $(".selected").attr('id');
var my_id = $(".selected").attr("value");
if($("#"+param+"").val() == "")
{
$("#"+param+"_id").val("");
}
selectOption(my_value, param, my_id);
$("#auto_"+param+"").slideUp();
$(".services").empty();
});
}
}
else
{
$("#auto_"+param+"").slideUp();
}
}
function selectOption(my_value, param, my_id)
{
$( "#"+param+"" ).val(my_value);
$( "#"+param+"_id" ).val(my_id);
$("#auto_"+param+"").slideUp();
}
</script>
</head>
<h3>For separating Email addresses use "," or ";"</h3>
<input type="text" class="" id="email_to" value="" placeholder="Enter Email" autocomplete="off"/>
<ul class="services" id="auto_email_to">
</ul>
</html>
<head>
<style>
#auto_email_to
{
border:1px solid #cccccc;
width:auto;
font-family:verdana, arial, helvetica, sans-serif;
font-size:15px;
height:auto;
margin-top:0px;
list-style:none;
position: absolute; /*display:none;*/
padding: 0;
background-color: #EAEAEA;
z-index:1;
box-shadow:6px 6px 8px #cccccc;
}
#auto_email_to li
{
height:25px;
}
#email_to
{
width:800px;
}
.services li.selected{
background-color:#636060;
color:#ffffff;
}
</style>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js" type="text/javascript">
</script>
<script>
var email_to = ["Albert@tom_jerry123.com","Allen@tom_jerry123.com","Aladin@tom_jerry123.com","Nilesh@tom_jerry123.com","Dharmesh@tom_jerry123.com","Aakesh@tom_jerry123.com","Pankaj@tom_jerry123.com","Vijay@fakebook.com","Manoj@fakebook.com","Zahir@fakebook.com","Mukesh@fakebook.com","Kishor@fakebook.com","Sachin@fakebook.com","Rakesh@fakebook.com"];
$(document).ready(function(){
var seperator = "";
//alert(123);
if($("#email_to").length > 0)
{
$("#email_to").unbind('keyup').keyup(function(e){
var str = $("#email_to").val();
var last_char = str.slice(-1);
if(last_char == ",")
{
seperator = ",";
}
else if(last_char == ";")
{
seperator = ";";
}
if(seperator == ",")
{
if(str.lastIndexOf(",") == -1)
{
//var Index = "";
}
else
{
var Index = str.lastIndexOf(",")+1;
}
}
else if(seperator = ";")
{
if(str.lastIndexOf(";") == -1)
{
//var Index = "";
}
else
{
var Index = str.lastIndexOf(";")+1;
}
}
if(Index < str.length)
{
var result = str.substring(str.lastIndexOf(""+seperator+"") + 1);
if(e.keyCode == 13)
{//("Enter");
var text_value = $("#email_to").val();
var sub_val = text_value.substring(0,text_value.lastIndexOf(""+seperator+""));
var my_value = $(".selected").attr('id');
var final_value = sub_val + seperator + " " + my_value;
if(my_value != undefined)
{
$( "#email_to" ).val(final_value);
$( "#email_to" ).focus();
$("#auto_email_to").slideUp();
$(".services").empty();
}
}
else if(e.keyCode == 38)
{ //up
var selected = $(".selected");
$(".services li").removeClass("selected");
//alert(selected.prev().length);
// if there is no element before the selected one, we select the last one
if (selected.prev().length == 0)
{
var child = selected.siblings().length + 1;
//alert(child);
$(".services li:nth-child("+child+")").addClass("selected");
}
else
{ // otherwise we just select the next one
selected.prev().addClass("selected");
}
}
else if(e.keyCode == 40)
{ //down
var selected = $(".selected");
$(".services li").removeClass("selected");
if (selected.next().length == 0)
{
$(".services li:nth-child(1)" ).addClass("selected");
}
else
{
selected.next().addClass("selected");
}
}
else
{
call_email(result, "email_to", seperator);
}
}
else
{
if(e.keyCode == 13)
{ // enter
if ($(".services").is(":visible"))
{
my_value = $(".selected").attr('id');
$( "#email_to" ).val(my_value);
$(".product_class").empty();
$(".services").empty();
$("#auto_email_to").slideUp();
}
else
{
$(".services").show();
}
//menuOpen = !menuOpen;
}
else if(e.keyCode == 38)
{ // up
var selected = $(".selected");
$(".services li").removeClass("selected");
// if there is no element before the selected one, we select the last one
if (selected.prev().length == 0)
{
var child = selected.siblings().length + 1;
$(".services li:nth-child("+child+")").addClass("selected");
}
else
{ // otherwise we just select the next one
selected.prev().addClass("selected");
}
}
else if(e.keyCode == 40)
{ // down
var selected = $(".selected");
$(".services li").removeClass("selected");
if (selected.next().length == 0)
{
$(".services li:nth-child(1)" ).addClass("selected");
}
else
{
selected.next().addClass("selected");
}
}
else
{
call_name("email_to");
}
}
});
}
});
function call_email(value, param, seperator)
{
//alert(seperator);
$(".services").empty();
var biller_name = value.toUpperCase().trim();
//alert(biller_name + " " + param);
var container = "";
$("#auto_"+param+"").empty();
if(biller_name != "")
{
if(param == "email_to")
{
var j = 0;
for(i=0;i<email_to.length;i++)
{
container = email_to[i].toUpperCase().toString();
if(container.indexOf(biller_name) >= 0)http://jsfiddle.net/7418/hzZJA/1/
{
if(j == 0){var selected = 'selected';}else{var selected = 'abc';}
$("#auto_"+param+"").append("<li class='listing "+selected+"' id='"+email_to[i]+"'>"+email_to[i]+"</li>");
j++;
}
else
{
$(".services").hide();
}
}
}
$("#auto_"+param+"").slideDown();
$(".services li").mouseover(function() {
//alert(param);
http://jsfiddle.net/7418/hzZJA/1/ $(".services li").removeClass("selected");
$(this).addClass("selected");
});
$(".services li").click(function() {
var text_value = $("#"+param+"").val();
var sub_val = text_value.substring(0,text_value.lastIndexOf(""+seperator+""));
//alert(sub_val);
var my_value = $(this).attr('id');
var final_value = sub_val + seperator + " " + my_value;
selectOption(final_value, param);
$("#"+param+"").focus();
$(".services").empty();
$("#auto_"+param+"").slideUp();
});
}
else
{
$("#auto_"+param+"").slideUp();
}
}
function call_name(param)
{
$(".services").empty();
//alert(param);
var temp_name = $("#"+param+"").val().toUpperCase().trim();
var container = "";
$("#auto_"+param+"").empty();
if(temp_name != "")
{
if(param == "email_to")
{
var j = 0;
for(i=0;i<email_to.length;i++)
{
container = email_to[i].toUpperCase().toString();
if(container.indexOf(temp_name) >= 0)
{
if(j == 0){var selected = 'selected';}else{var selected = 'abc';}
$("#auto_"+param+"").append("<li class='listing "+selected+"' id='"+email_to[i]+"'>"+email_to[i]+"</li>");
j++;
}
else
{
$("#auto_"+param+"").hide();
}
}
}
$(".services li").mouseover(function()
{
$(".services li").removeClass("selected");
$(this).addClass("selected");
});
$(".services li").click(function() {
var my_value = $(this).attr('id');
selectOption(my_value, param);
$(".product_class").empty();
$(".services").empty();
});
var my_width = $("#"+param+"").width() + 5;
$("#auto_"+param+"").width(my_width);
$("#auto_"+param+"").width(my_width);
$("#auto_"+param+"").slideDown();
if(param != "email_to")
{
$("#"+param+"").unbind('blur').blur(function() {
var my_value = $(".selected").attr('id');
var my_id = $(".selected").attr("value");
if($("#"+param+"").val() == "")
{
$("#"+param+"_id").val("");
}
selectOption(my_value, param, my_id);
$("#auto_"+param+"").slideUp();
$(".services").empty();
});
}
}
else
{
$("#auto_"+param+"").slideUp();
}
}
function selectOption(my_value, param, my_id)
{
$( "#"+param+"" ).val(my_value);
$( "#"+param+"_id" ).val(my_id);
$("#auto_"+param+"").slideUp();
}
</script>
</head>
<h3>For separating Email addresses use "," or ";"</h3>
<input type="text" class="" id="email_to" value="" placeholder="Enter Email" autocomplete="off"/>
<ul class="services" id="auto_email_to">
</ul>
</html>
Live Demo :
Wednesday, 9 July 2014
HTML5 canvas using JavaScript
The canvas is HTML5 element used to draw graphics using JavaScript.
<!DOCTYPE html>
<html>
<body>
<canvas id="myCanvas" style="border:1px solid #000000;">Your browser does not support the HTML5 canvas tag.</canvas>
<script>
var c=document.getElementById('myCanvas');
var ctx=c.getContext('2d');
//ctx.fillStyle='#FF0000';
for (var x = 0, y = 0; x < 150 && y < 200; x += 50, y += 37) {
var i = x+125;
var color ='FF0'+i;
//alert(color);
ctx.fillStyle='#'+color;
ctx.fillRect(x,y,60,60);
}
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<body>
<canvas id="myCanvas" style="border:1px solid #000000;">Your browser does not support the HTML5 canvas tag.</canvas>
<script>
var c=document.getElementById('myCanvas');
var ctx=c.getContext('2d');
//ctx.fillStyle='#FF0000';
for (var x = 0, y = 0; x < 150 && y < 200; x += 50, y += 37) {
var i = x+125;
var color ='FF0'+i;
//alert(color);
ctx.fillStyle='#'+color;
ctx.fillRect(x,y,60,60);
}
</script>
</body>
</html>
Thursday, 3 July 2014
Fetch GooglePlus Feeds using PHP
<?php function fetchAPI($url) {
$content = '';
if (ini_get('allow_url_fopen') == true) {
$content = file_get_contents($url);
}
else {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url . $key);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$content = curl_exec($ch);
curl_close($ch);
}
return $content;
}
// Google+ ID
$googlePlusID = 'YOUR ID';
$url = "https://plus.google.com/YOUR ID/posts";
// Google+ API key
$key = 'DEVELOPER KEY';
$url = 'https://www.googleapis.com/plus/v1/people/' . $googlePlusID . '/activities/public?alt=json&pp=1&key=';
$content = fetchAPI($url . $key);
if ($content)
file_put_contents($cacheFile, $content);
if (!$content)
die('Failed to load G+ data');
$gplus = json_decode($content);
if (!$gplus)
die('Failed to decode G+ data');
echo "<pre>";
print_r($gplus);
die;
Sunday, 22 June 2014
File Upload and Delete multiple rows by selecting checkboxes using PHP
Index Page :
<html>
<head></head>
<body>
<form name="frm" method="post" action="submit.php" enctype="multipart/form-data">
<table>
<tr>
<td> Student Name </td>
<td><input type="text" name="stu_name"/><td>
<tr>
<tr>
<td> Student Email </td>
<td><input type="text" name="stu_email"/><td>
<tr>
<tr>
<td> Student Phone </td>
<td><input type="text" name="stu_phone"/><td>
<tr>
<tr>
<td> Student Photo </td>
<td><input type="file" name="stu_photo"/><td>
<tr>
<tr colspan="2">
<td><input type="submit" value="submit data" name="submit"></td>
</tr>
</table>
</form>
<form name="frm1" method="post" action="submit.php" enctype="multipart/form-data">
<table>
<tr>
<td><input type="checkbox" name="check_all"/>
<td>ID</td>
<td> Name</td>
<td> Email</td>
<td> phone</td>
<td>photo </td>
</tr>
<?php
$con = mysql_connect("localhost","root","");
mysql_select_db("pan_test",$con);
$query = mysql_query("select * from stu_info");
while($row = mysql_fetch_array($query)){
$id = $row['id'];
$name = $row['name'];
$email = $row['email'];
$phone = $row['phone'];
$photo = $row['photo'];
echo "<tr>";
echo "<td><input type='checkbox' name='checkbox[]' value='$id'/></td>";
echo "<td>$name</td>";
echo "<td>$email</td>";
echo "<td>$phone</td>";
//echo "<td><img src='uploads/$photo'/><td>";
echo "</tr>";
}
?>
<tr colspan="2">
<td><input type="submit" value="submit data" name="submit1"></td>
</tr>
</body>
</html>
submit.php
<?php
$con = mysql_connect("localhost","root","");
mysql_select_db("pan_test",$con);
if($_REQUEST['submit']){
$name= $_REQUEST['stu_name'];
if(empty($name)){
echo "missing";
}
$mail= $_REQUEST['stu_email'];
$phone=$_REQUEST['stu_phone'];
$photo= $_FILES['stu_photo'] ['name'];
$target = 'uploads/'.basename($_FILES['stu_photo'] ['name']);
move_uploaded_file($_FILES['stu_photo'] ['tmp_name'],$target);
$query = mysql_query("insert into stu_info(name,email,phone,photo) values('$name','$mail','$phone','$photo')");
header('location: index.php');
}
else if($_REQUEST['submit1']){
print_r($_REQUEST);
$checkbox= $_REQUEST['checkbox'];
for($i=0;$i<count($_REQUEST['checkbox']);$i++){
echo $id= $checkbox[$i];
$query = mysql_query("delete from stu_info where id=$id");
}
}
?>
<html>
<head></head>
<body>
<form name="frm" method="post" action="submit.php" enctype="multipart/form-data">
<table>
<tr>
<td> Student Name </td>
<td><input type="text" name="stu_name"/><td>
<tr>
<tr>
<td> Student Email </td>
<td><input type="text" name="stu_email"/><td>
<tr>
<tr>
<td> Student Phone </td>
<td><input type="text" name="stu_phone"/><td>
<tr>
<tr>
<td> Student Photo </td>
<td><input type="file" name="stu_photo"/><td>
<tr>
<tr colspan="2">
<td><input type="submit" value="submit data" name="submit"></td>
</tr>
</table>
</form>
<form name="frm1" method="post" action="submit.php" enctype="multipart/form-data">
<table>
<tr>
<td><input type="checkbox" name="check_all"/>
<td>ID</td>
<td> Name</td>
<td> Email</td>
<td> phone</td>
<td>photo </td>
</tr>
<?php
$con = mysql_connect("localhost","root","");
mysql_select_db("pan_test",$con);
$query = mysql_query("select * from stu_info");
while($row = mysql_fetch_array($query)){
$id = $row['id'];
$name = $row['name'];
$email = $row['email'];
$phone = $row['phone'];
$photo = $row['photo'];
echo "<tr>";
echo "<td><input type='checkbox' name='checkbox[]' value='$id'/></td>";
echo "<td>$name</td>";
echo "<td>$email</td>";
echo "<td>$phone</td>";
//echo "<td><img src='uploads/$photo'/><td>";
echo "</tr>";
}
?>
<tr colspan="2">
<td><input type="submit" value="submit data" name="submit1"></td>
</tr>
</body>
</html>
submit.php
<?php
$con = mysql_connect("localhost","root","");
mysql_select_db("pan_test",$con);
if($_REQUEST['submit']){
$name= $_REQUEST['stu_name'];
if(empty($name)){
echo "missing";
}
$mail= $_REQUEST['stu_email'];
$phone=$_REQUEST['stu_phone'];
$photo= $_FILES['stu_photo'] ['name'];
$target = 'uploads/'.basename($_FILES['stu_photo'] ['name']);
move_uploaded_file($_FILES['stu_photo'] ['tmp_name'],$target);
$query = mysql_query("insert into stu_info(name,email,phone,photo) values('$name','$mail','$phone','$photo')");
header('location: index.php');
}
else if($_REQUEST['submit1']){
print_r($_REQUEST);
$checkbox= $_REQUEST['checkbox'];
for($i=0;$i<count($_REQUEST['checkbox']);$i++){
echo $id= $checkbox[$i];
$query = mysql_query("delete from stu_info where id=$id");
}
}
?>
Saturday, 21 June 2014
Database Connectivity using Type I - JDBC Driver in Java(J2SE)
What is JDBC?
Statement st = con.createStatement();
Step 4) Prepare a query and execute the query at backend database.
Step 5) Close all connections:
st.close();
con.close();
Sample JDBC code for this demonstration:
import java.sql.*;
class DBConnectivity
{
public static void main( String [] args)
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn = DriverManager.getConnection("jdbc:odbc:OracleDSN","scoot","tiger");
Statement st = conn.createStatement();
boolean flag = st.execute("create table student(ID varchar2(5), NAME varchar2(30), MARKS number(5))");
int x = st.executeUpdate("inser into stud values('101','Pallavi',879)");
ResultSet rs = st.executeQuery("<SELECT ID,NAME,MARKS from student>");
while (re.nwex())
{
logout("ID:-"+rs.getString(1)+"\t");
logout("NAME:-"+rs.getString(2)+"\t");
logout("MARKS:-"+rs.getInt(3)+"\n");
}
}
public void logout(String msg)
{
System.out.println(msg);
}
}
Note: Here "OracleDSN" is User Created DSN (Data Source Name), in Administrative Tools-->Data Source
- JDBC(Java DataBase Connectivity) is used for connecting to different database by which user can shift from one database to another database very easily in platform independent manner.
- JDBC contains set of functions & specification in the form of packages i.e.:
- java.sql.*--Core SQL Package
- javax.sql.*--Extended SQL Package
- JDBC Driver act like an interface between front end application and back end database.
- There are four types of JDBC Driver
- Type I-ODBC(Open DataBase Connectivity) Bridge Driver
- Type II-Java Native Interface Driver
- Type III-Net Protocol Driver
- Type-IV-Native Protocol Drover
- Type I Driver, there exist an implementation class by which user can be able to connect to different database.
- This implementation class, named JdbcOdbcDriver.class is provided within rt.jar file.
Connecting to any Database:-
Step 1) Loading a Driver:
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Step 2) Getting Connection:
Connection con = DriverManager.getConnection("<URL>","<UserName>","<Password>");
Step 3) Create Statement Object:
Statement st = con.createStatement();
Step 4) Prepare a query and execute the query at backend database.
- ResultSet rs = st.executeQuery("<SQL SELECT command>");
- boolean flag = st.execute("<SQL Non-SELECT command>");
- int x = st.executeUpdate("<SQL DML command>");
Step 5) Close all connections:
st.close();
con.close();
Sample JDBC code for this demonstration:
import java.sql.*;
class DBConnectivity
{
public static void main( String [] args)
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn = DriverManager.getConnection("jdbc:odbc:OracleDSN","scoot","tiger");
Statement st = conn.createStatement();
boolean flag = st.execute("create table student(ID varchar2(5), NAME varchar2(30), MARKS number(5))");
int x = st.executeUpdate("inser into stud values('101','Pallavi',879)");
ResultSet rs = st.executeQuery("<SELECT ID,NAME,MARKS from student>");
while (re.nwex())
{
logout("ID:-"+rs.getString(1)+"\t");
logout("NAME:-"+rs.getString(2)+"\t");
logout("MARKS:-"+rs.getInt(3)+"\n");
}
}
public void logout(String msg)
{
System.out.println(msg);
}
}
Note: Here "OracleDSN" is User Created DSN (Data Source Name), in Administrative Tools-->Data Source
Subscribe to:
Posts (Atom)