Sunday, October 21, 2007

How to insert data using AJAX , Both GET and POST method (PHP)

Ajax - Browser Specific Code, just copy and paste below code. This code is for browser specific.

var request = false;
var xmlString;
var microsoft = true;
var updatePage;

function initAjax()
{
try
{
request = new XMLHttpRequest(); // Ajax Class for Mozilla based browsers
microsoft = false;
}
catch (trymicrosoft)
{
try
{
request = new ActiveXObject("Msxml2.XMLHTTP"); // Ajax Class for IE
}
catch (othermicrosoft)
{
try
{
request = new ActiveXObject("Microsoft.XMLHTTP"); // Ajax Class for Mozilla based browsers
}
catch (failed)
{
request = false;
}
}
}


This code is must for all AJAX based coding.



Ajax - onreadystatechange Property


Before we even think about sending data to the server, we must first write a function that will be able to receive information. This function will be used to catch the data that is returned by the server.

The XMLHttpRequest object has a special property called onreadystatechange. onreadystatechange stores the function that will process the response from the server. The following code defines an empty function and sets the onreadystatechange property at the same time!

We will be filling this function in throughout the lesson, as you learn more about the XMLHttpRequest object.


I am writing this as a function.

function updatePage()
{
if (request.readyState== 4 || request.readyState=="complete")
{
if(request.status == 200)
{
var obj = document.getElementById('success');
xmlString = request.responseText;
obj.innerHTML=xmlString;
}
else
{
alert("Error :" + request.status );
}
}
}

For GET Method

function addStaff()
{

initAjax();
var obj = document.getElementById('success');
obj.innerHTML="";
var url = "add_data.php";


var name = document.getElementById("name").value;
var password = document.getElementById("password").value;


request.open("GET", url+"?bustcache="+new Date().getTime()+"&name="+name+"&password="+password,true);



request.onreadystatechange = updatePage1;
request.send(null);

}




For POST Method



function submitForm()
{

initAjax();

var name = document.getElementById("name").value;
var password= document.getElementById("password").value;
var obj = document.getElementById('success1');
obj.innerHTML="";

var url = "ajax_output.php";
var passData = '&name='+name+'&password='+password;

request.open("POST", url, true);
request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
request.onreadystatechange = updatePage;
request.send(passData);



}

Friday, August 17, 2007

Php installation in windows/Linux etc...

These are some method to install apahe/php/mysql/phpMyadmin into your system

This is a built in web server that is automatically configured when you install it.

Go through below links

For windows

http://www.wampserver.com/en/index.php

and

http://www.apachefriends.org/en/xampp-windows.html

XAMPP for linux also

http://www.apachefriends.org/en/xampp-linux.html

and for other OS

http://www.apachefriends.org/en/xampp.html

Thursday, August 16, 2007

Some Nice Site for PHP,MySql,Ajax etc for Beginners

Php,MySql, Ajax,XML,JavaScript, etc

http://www.w3schools.com/

http://www.tizag.com/

For PHP


http://php.net/

For pear

http://pear.php.net/


For Smarty

http://smarty.php.net/

Image to Flash convert code using PHP

convery.php

require("class.imageconverter.php");

$img = new ImageConverter("image.jpg","swf");

?>

class.imageconverter.php


class ImageConverter {

var $imtype;
var $im;
var $imname;
var $imconvertedtype;
var $output;

function imageConverter() {

/* parse arguments */
$numargs = func_num_args();
$imagefile = func_get_arg(0);
$convertedtype = func_get_arg(1);
$output = 0;
if($numargs > 2) $this->output = func_get_arg(2);

/* ask the type of original file */
$fileinfo = pathinfo($imagefile);
$imtype = $fileinfo["extension"];
$this->imname = basename($fileinfo["basename"],".".$imtype);
$this->imtype = $imtype;

/* create the image variable of original file */
switch ($imtype) {
case "gif":
$this->im = imageCreateFromGIF($imagefile);
break;
case "jpg":
$this->im = imageCreateFromJPEG($imagefile);
break;
case "png":
$this->im = imageCreateFromPNG($imagefile);
break;
case "wbmp":
$this->im = imageCreateFromWBMP($imagefile);
break;
/*
mail me if you have/find this functionality bellow */
/*
case "swf":
$this->im = $this->imageCreateFromSWF($imagefile);
break;
*/
}

/* convert to intended type */
$this->convertImage($convertedtype);
}

function convertImage($type) {

/* check the converted image type availability,
if it is not available, it will be casted to jpeg :) */
$validtype = $this->validateType($type);


if($this->output) {

/* show the image */
switch($validtype){
case 'jpeg' :
case 'jpg' :
header("Content-type: image/jpeg");
if($this->imtype == 'gif' or $this->imtype == 'png') {
$image = $this->replaceTransparentWhite($this->im);
imageJPEG($image);
} else
imageJPEG($this->im);
break;
case 'gif' :
header("Content-type: image/gif");
imageGIF($this->im);
break;
case 'png' :
header("Content-type: image/png");
imagePNG($this->im);
break;
case 'wbmp' :
header("Content-type: image/vnd.wap.wbmp");
imageWBMP($this->im);
break;
case 'swf' :
header("Content-type: application/x-shockwave-flash");
$this->imageSWF($this->im);
break;
}

} else {
/* save the image */
switch($validtype){
case 'jpeg' :
case 'jpg' :
if($this->imtype == 'gif' or $this->imtype == 'png') {
/* replace transparent with white */
$image = $this->replaceTransparentWhite($this->im);
imageJPEG($image,$this->imname.".jpg");
} else
imageJPEG($this->im,$this->imname.".jpg");
break;
case 'gif' :
imageGIF($this->im,$this->imname.".gif");
break;
case 'png' :
imagePNG($this->im,$this->imname.".png");
break;
case 'wbmp' :
imageWBMP($this->im,$this->imname.".wbmp");
break;
case 'swf' :
$this->imageSWF($this->im,$this->imname.".swf");
break;

}

}
}

/* convert image to SWF */
function imageSWF() {

/* parse arguments */
$numargs = func_num_args();
$image = func_get_arg(0);
$swfname = "";
if($numargs > 1) $swfname = func_get_arg(1);

/* image must be in jpeg and
convert jpeg to SWFBitmap
can be done by buffering it */
ob_start();
imagejpeg($image);
$buffimg = ob_get_contents();
ob_end_clean();

$img = new SWFBitmap($buffimg);

$w = $img->getWidth();
$h = $img->getHeight();

$movie = new SWFMovie();
$movie->setDimension($w, $h);
$movie->add($img);

if($swfname)
$movie->save($swfname);
else
$movie->output;

}


/* convert SWF to image */
function imageCreateFromSWF($swffile) {

die("No SWF converter in this library");

}

function validateType($type) {
/* check image type availability*/
$is_available = FALSE;

switch($type){
case 'jpeg' :
case 'jpg' :
if(function_exists("imagejpeg"))
$is_available = TRUE;
break;
case 'gif' :
if(function_exists("imagegif"))
$is_available = TRUE;
break;
case 'png' :
if(function_exists("imagepng"))
$is_available = TRUE;
break;
case 'wbmp' :
if(function_exists("imagewbmp"))
$is_available = TRUE;
break;
case 'swf' :
if(class_exists("swfmovie"))
$is_available = TRUE;
break;
}
if(!$is_available && function_exists("imagejpeg")){
/* if not available, cast image type to jpeg*/
return "jpeg";
}
else if(!$is_available && !function_exists("imagejpeg")){
die("No image support in this PHP server");
}
else
return $type;
}

function replaceTransparentWhite($im){
$src_w = ImageSX($im);
$src_h = ImageSY($im);
$backgroundimage = imagecreatetruecolor($src_w, $src_h);
$white = ImageColorAllocate ($backgroundimage, 255, 255, 255);
ImageFill($backgroundimage,0,0,$white);
ImageAlphaBlending($backgroundimage, TRUE);
imagecopy($backgroundimage, $im, 0,0,0,0, $src_w, $src_h);
return $backgroundimage;
}
}
?>

Currency Converter Using PHP

below function used to convert one currency to another

function get_conversion($cur_from,$cur_to){
if(strlen($cur_from)==0){
$cur_from = "USD";
}
if(strlen($cur_to)==0){
$cur_from = "PHP";
}
$host="finance.yahoo.com";
$fp = @fsockopen($host, 80, $errno, $errstr, 30);
if (!$fp)
{
$errorstr="$errstr ($errno)
\n";
return false;
}
else
{
$file="/d/quotes.csv";
$str = "?s=".$cur_from.$cur_to."=X&f=sl1d1t1ba&e=.csv";
$out = "GET ".$file.$str." HTTP/1.0\r\n";
$out .= "Host: www.yahoo.com\r\n";
$out .= "Connection: Close\r\n\r\n";
@fputs($fp, $out);
while (!@feof($fp))
{
$data .= @fgets($fp, 128);
}
@fclose($fp);
@preg_match("/^(.*?)\r?\n\r?\n(.*)/s", $data, $match);
$data =$match[2];
$search = array ("']*?>.*?'si","'<[\/\!]*?[^<>]*?>'si","'([\r\n])[\s]+'","'&(quot|#34);'i","'&(amp|#38);'i","'&(lt|#60);'i","'&(gt|#62);'i","'&(nbsp|#160);'i","'&(iexcl|#161);'i","'&(cent|#162);'i","'&(pound|#163);'i","'&(copy|#169);'i","'&#(\d+);'e");
$replace = array ("","","\\1","\"","&","<",">"," ",chr(161),chr(162),chr(163),chr(169),"chr(\\1)");
$data = @preg_replace($search, $replace, $data);
$result = split(",",$data);
return $result[1];
}//else
}//end get_conversion

$value =2;
$x = get_conversion('USD','EUR');
$x = $x * $value;


echo "Conversion Result : ".$x."";
?>

$value means 1,2 etc that means 1 USD = -- EUR
etc

below are the currency names

Installing Apache PHP and MySQL

PHP and MySQL are usually associated with LAMP (Linux, Apache, MySQL, PHP). However, most PHP developer ( including me ) are actually using Windows when developing the PHP application. So this page will only cover the WAMP ( Windows, Apache, MySQL, PHP ). You will learn how to install Apache, PHP, and MySQL under Windows platform.

The first step is to download the packages :

You should get the latest version of each packages. As for the example in this tutorial i'm using Apache 2.0.50 ( apache_2.0.50-win32-x86-no_ssl.msi ), PHP 4.3.10 ( php-4.3.10-Win32.zip ) and MySQL 4.0.18 ( mysql-4.0.18-win.zip ).

Now let's start the installation process one by one.

Go through below links for more details : -

http://www.php-mysql-tutorial.com/install-apache-php-mysql.php

Enable curl with XAMPP on Windows XP

To enable curl library with XAMPP we need to modify the php.ini files in our xampp folder.

1) Locate the following files:
C:\Program Files\xampp\apache\bin\php.ini
C:\Program Files\xampp\php\php.ini
C:\Program Files\xampp\php\php4\php.ini

2) Uncomment the following line on your php.ini file by removing the semicolon.

;extension=php_curl.dll

3) Restart your apache server.

4) Check your phpinfo if curl was properly enabled.

Thursday, April 5, 2007

YouTube user removes clip mocking Thai king


The anonymous creator of a 44-second video clip mocking Thailand's revered king removed it from the YouTube video-sharing Web site on Thursday after torrents of abuse from outraged Thai viewers.

The relevant page on YouTube said simply the video had "been removed by the user".

However, Communications Minister Sitthichai Pookaiyaudom said Bangkok's army-backed administration would continue to block YouTube (www.youtube.com) as two images deemed offensive remained.

"We want those photos off the site too," he told Reuters.

Earlier, Sitthichai accused YouTube, owned by Internet search engine Google Inc, of being heartless and culturally insensitive for refusing to remove the file.

"We have told them how deeply offended Thais were by the clip, but they said there was much worse ridicule of President Bush on the site and they kept that there," he said.

"I don't think they really care how we feel. Thailand is only a tiny market for them."

The video showed grainy pictures of King Bhumibol Adulyadej, the world's longest-reigning monarch whom many of Thailand's 63 million people regard as a semi-divine "father of the nation", with crude graphics superimposed on his face.

The most offensive image to Thais was the imposition of a pair of woman's feet, the lowest part of the body, on his head.

YouTube, which has dominated the user-generated online video market since it was founded in February last year, said it was disappointed by Bangkok's move and was "looking into the matter".

"YouTube reaches a wide global audience and strives to provide a community where people from around the world can express themselves by sharing videos in a safe and lawful manner," the company said in an e-mail response to Reuters.

Criticising or offending royalty is a serious crime in Thailand. Those found guilty of lese majeste can be jailed for up to 15 years.

Last week, a 57-year-old Swiss man was sentenced to 10 years in jail for spraying graffiti on pictures of the king on his birthday in December, a rare prison term for a foreigner.

However, the generals who ousted elected Prime Minister Thaksin Shinawatra in a coup last September have also used the lese majeste laws to stifle criticism of themselves or their actions.

Several Web sites calling into question the southeast Asian nation's 18th coup in 75 years of on-off democracy have been shut down by the army-installed government.

When reports of the offending royal YouTube clip emerged in Thailand, the number of views rocketed by 50,000 in less than 24 hours, according to the site's own data.

It generated a lively debate about freedom of expression although the main reaction from Thais was shock and outrage - and torrents of abuse at the clip's creator, "paddidda", who is based in the United States.

Google turns to users for online maps


Google Inc. (NASDAQ:GOOG) is calling upon its millions of users to chart a new direction for its online maps. As part of an initiative being launched Thursday, the Internet search leader will provide free tools designed to make it easy for people to share their knowledge about their neighborhoods and other favorite places by creating customized maps that can assemble information from a variety of sources. The map creators will be given the option to make the content public or keep it private. Thousands of hybrid maps, often called 'mashups,' are already available on the Web, documenting everything from local housing markets to active volcanos. But cobbling together an online map typically requires some computer coding skills. Google has tailored its tools for a mass audience, making map mashups as easy to produce as pointing and clicking a computer mouse. The Mountain View-based company is hoping the simplicity will generate millions of highly specialized maps that can be stored in its search index. Until now, Google's two-year-old maps had primarily been used for driving directions and finding local businesses. The more personal maps should open up new avenues as users share insights about their favorite vacation spots or a wide range of academic subjects, said Jessica Lee, product manager of Google maps. 'This is a big change,' Lee said. 'Even if we cut loose all our developers, we could never create maps with the same depth and quality as our users can.' While testing the new tools, Google's own engineers created maps focused on U.S. Route 66, the Hawaiian island of Kauai, Major League Baseball stadiums and voting patterns in the 2004 presidential election. If Google succeeds in its effort to build a vast storehouse of customized maps, its Web site could become an even more popular Internet destination. Achieving that goal would give Google even more opportunities to display the online ads that accounted for most of its $3.1 billion profit last year. The feature also could drive more traffic to Google's YouTube because the new toolkit also includes an option to embed video into the customized maps. Google's maps already are a big draw, with 22.2 million U.S. visitors during February, according to the most recent data available from comScore Media Metrix. That ranked Google maps third in its category, trailing AOL's Mapquest (45.1 million visitors) and Yahoo (NASDAQ:YHOO) (29.1 million visitors). The concept of mapping mashups was popularized by a computer animation engineer, Paul Rademacher, who charted apartment listings from Craigslist. Google has since hired Rademacher to work in its mapping department. Copyright 2007 Associated Press. All rights reserved. This material may not be published, broadcast, rewritten, or redistributed.

CNN

Warming 'already changing world'

Climate change is already having major impacts on the natural world, a UN report is set to announce.

The Intergovernmental Panel on Climate Change (IPCC) believes there is also a discernible, though less marked, impact on human societies.

The IPCC is to release a summary of its report on Friday but talks on wording have continued late into the night.

Officials said there were differences between various countries on the strength of the language.


"The Europeans want to send a strong signal. The US does not want as much quantification," one official told the French news agency AFP.

China and Russia had also raised concerns over some passages of the 21-page summary, the official said.

The last-minute wrangling is likely to affect the degree of certainty in the final version, the BBC's Richard Black reports, but not the overall direction.

Water shortages

Draft versions seen by BBC News warn it will be hard for societies to adapt to all the likely climate impacts.

The report is set to say that a temperature rise above 1.5C from 1990 levels would put about one-third of species at risk of extinction.

More than one billion people would be at greater risk of water shortages, primarily because of the melting of mountain glaciers and ice fields which act as natural reservoirs.

The scientific work reviewed by IPCC scientists includes more than 29,000 pieces of data on observed changes in physical and biological aspects of the natural world.

Eighty-five percent of these, it believes, are consistent with a warming world.

Growing certainty

Since the IPCC's last global assessment in 2001, the amount of scientific work on observing and collating changes to the natural world has vastly increased.

In parallel, computer models which project the Earth's climatic future have grown ever more sophisticated, though there are still uncertainties in their forecasts and they remain unable to model some physical processes accurately.

The combination of more observational evidence and better models allows scientists to paint a much more detailed picture of what is happening in different regions of the world, and what they believe is likely to happen in the future.

"What we find is that evidence of the impacts of climate change is much sharper, much more reliable," said IPCC chair Rajendra Pachauri.

A fisherman drags fish at the drying Dongting Lake on January 11, 2007

"Many of the uncertainties have been resolved; and they confirm that the poorest of the poor are most likely to be hit by the impacts of climate change."

Fresh water is perhaps the most serious issue for human societies.

The world's great mountain ranges, such as the Himalayas, Rockies, Andes and Alps, act as natural reservoirs, trapping winter rain and snowfall as ice, and releasing it gradually in the summer.

Evidence suggests that glaciers are shrinking in all of these ranges. One recent study predicted that 75% of Alpine glaciers would have vanished by the end of this century.

As the ice disappears, spring and autumn floods become more likely, with an increased risk of drought in summer. The IPCC is expected to say there is "very high confidence" that these trends are already occurring.

It will also project a higher risk of flooding for many major cities on or near the coast.

Carbon cuts

Some observers of climate issues have long maintained that action on climate change should focus on protecting societies and natural systems against impacts such as floods and drought, rather than on curbing greenhouse gas emissions.

Dealing with drought

The IPCC, however, is set to conclude that "adaptation alone is not expected to cope with all the projected effects of climate change, and especially not over the long run as most impacts increase in magnitude".

Poorer societies are likely to be hardest hit, as they lack the resources to set up protective measures and change their economic base.

Adapting to climate impacts, in the IPCC's view, should go hand in hand with reducing emissions.

This is the second in a series of IPCC reports coming out this year, together making up its fourth global climate assessment.

The first element, on the science of climate change, was released in February, concluding it is at least 90% likely that human activities are principally responsible for the warming observed since 1950.

The third part, which comes out in May, will focus on ways of curbing the rise in greenhouse gas concentrations and temperature.

BBC

Monday, February 19, 2007

1000 Hyderbad IT professionals fired!

It is sleepless nights for Hyderabad's IT employees. About a 1000 lost their jobs overnight after they failed their employers' background checks. CNBC-TV18 gives the details.

It has been a harrowing week for Satyam's
staff, as 500 of their work mates have already been fired overnight. That is after the company conducted background checks on its middle and junior-level employees to curb fraud and minimise the risk of data theft.

But Satyam is not alone. HSBC too fired over 350 employees at its call centre in Hyderabad over the past week. Officials from Satyam say it is conducting checks at all its facilities in India and if an employee is found to have falsified any certification, he or she is being asked to leave immediately.

Satyam officials say they will not file criminal proceedings, but other IT and ITeS companies have begun similar checks. They hope to make their companies virtually fraud free.

Thursday, February 15, 2007

Amnesty honour for Jennifer Lopez


Hollywood star Jennifer Lopez has been honoured by human rights group Amnesty International for her latest film.

Bordertown is set in the Mexican town of Ciudad Juarez, which has witnessed a grisly decade of unsolved rapes and murders of young women.

Lopez, who produced the movie, stars as an investigative journalist reporting on the serial killings.

She was awarded the Artists for Amnesty prize ahead of the film's premiere at the Berlin Film Festival on Wednesday.

The actress, 37, said she was "very humbled" as she was given the award by East Timor's Prime Minister Jose Ramos-Horta, a Nobel peace laureate.

'Shocking'

No-one knows how many murders have been committed in Ciudad Juarez since the killings began in 1993, but Amnesty says it is more than 400.

Police have made several arrests, and the murders have been variously attributed to serial killers, drug cartels and domestic violence.

Several gangs have also been mentioned as the perpetrators.

But every time the police trumpet an arrest or conviction, the murders continue.

Lopez described the situation as "one of the world's most shocking and disturbing, underreported crimes against humanity."

Also at the Amnesty ceremony in Berlin was Norma Andrade, whose 17-year-old daughter was found murdered in February 2001.

Following her daughter's death, she co-founded Our Daughters Back Home (Nuestras Hijas de Regreso a Casa), a legal support group for victims' parents.

"She's a remarkable woman and a true inspiration," Lopez said.

Bordertown also stars Antonio Banderas and Martin Sheen. It does not yet have a release date.

Monday, February 12, 2007

Valentine's Day: The Good, The Bad, The Lovely

Once again, St. Valentine's universal day of affection has arrived. It is traditionally a day of euphoria, during which recipients of Cupid's arrows go about their day lulled by the warmth of romantic love and bubbly floating hearts that fill the air.

Reality check: It's freezing outside, and for many, Valentine's Day is not always the stereotypical love-fest it is sometimes made out to be. As these students prove, some of the most amusing stories are those of romance gone awry.

Premature proposal

Debbie Reedy's boyfriend could not wait until Valentine's Day to propose to his girlfriend of nearly a year, so he popped the question on Feb. 1 of this year.

Reedy, a sophomore early childhood education major, said she never even suspected he was going to ask her to marry him.

"I had just got out of the bath tub and he came in, and I was like wait a minute I'm not ready yet!" she said. "He was like, 'Don't make me yell at you before I propose to you.'"

Reedy's boyfriend did not have to yell, but instead told her he wanted to be her "only Valentine."

"I cried and said yes," Reedy said.

Too much love?

The men's chorus at Kent State University has traditionally provided a singing telegrams service on Valentine's Day. Sometimes members of the group practice their skills on unsuspecting victims.

Sophomore nursing major Lindsey Eble was one such victim. Two members of the chorus happened to be resident assistants in the hall she was living in.

"I got serenaded by my RAs in the middle of the Student Center," she said. "They were trying to advertise for it (singing telegrams). It was a little embarrassing."

Motherly love

Valentine's Day is known to be a day of love, but it doesn't always have to be romantic. For some, it can be about love between friends and family as well.

"My mom's always been my Valentine," said Patrice DeLeon, Kent State alumnus and volunteer for the university health center.

DeLeon said it started with a bad week she had during her senior year of high school. She failed a test, was a having problems with a guy she liked and was nervous for her brother, who was competing in an upcoming wrestling tournament — all during the week of Valentines Day.

"My mom actually bought me a half dozen roses and a Scooby Doo twin bed set that glowed in the dark," she said.

Now her mom calls her every Valentine's day, she said.

No "yolking"

Differing beliefs can be a big hurdle in relationships, but for Nik Kolenich, a freshman interior design major, and his ex-girlfriend, it was a deal breaker.

Kolenich's girlfriend of six months was a Christian who came from a Christian family. He was not.

"I took her out to this fancy Valentine's Day dinner, and I could tell there was some tension," he said.

During the dinner Kolenich' girlfriend broke up with him, citing their conflicting beliefs as their biggest problem.

"She said, 'We're not evenly yoked,'" Kolenich said. "It had something to do with religion, but all I could think about was scrambled eggs."

Bitter irony

Maddie Richards, freshman justice studies major, knows all too well that Valentine's Day can prove to be a painful experience.

"Last Valentine's Day I got a broken nose," she said.

Richards said another girl had a crush on Richards' boyfriend and was jealous of their relationship.

"She came over to his place while I was there," she said. "I told her to leave because it was my day with him."


Richards said the girl jumped on her, punched her in the face and then left.

Richards called the police, but when they arrived she was dealt another blow: Her boyfriend, who had a warrant out for his arrest, walked away from their celebration in handcuffs.

http://media.www.stateronline.com